@@ -17,16 +17,13 @@ install the Monolog based logger before using it:
1717 Logging a Message
1818-----------------
1919
20- To log a message, fetch the`` logger `` service from the container in
21- your controller ::
20+ If the application uses the:ref: ` default services.yaml configuration < service- container-services-load-example >`,
21+ you can get the logger service injecting the `` LoggerInterface `` class ::
2222
2323 use Psr\Log\LoggerInterface;
2424
25- public functionindexAction (LoggerInterface $logger)
25+ public functionindex (LoggerInterface $logger)
2626 {
27- // alternative way of getting the logger
28- // $logger = $this->get('logger');
29-
3027 $logger->info('I just got the logger');
3128 $logger->error('An error occurred');
3229
@@ -38,7 +35,7 @@ your controller::
3835 // ...
3936 }
4037
41- The`` logger `` service has different methods for different logging levels/priorities.
38+ The logger service has different methods for different logging levels/priorities.
4239You can configure the logger to do different things based on the *level * of a message
4340(e.g.:doc: `send an email when an error occurs </logging/monolog_email >`).
4441
@@ -47,10 +44,6 @@ See LoggerInterface_ for a list of all of the methods on the logger.
4744Where Logs are Stored
4845---------------------
4946
50- The configuration for *where * logs are stored lives in the specific
51- :doc: `environment </configuration/environments >` configuration files: ``config_dev.yml ``
52- and ``config_prod.yml ``.
53-
5447By default, log entries are written to the ``var/log/dev.log `` file when you're in
5548the ``dev `` environment. In the ``prod `` environment, logs are written to ``var/log/prod.log ``,
5649but *only * during a request where an error or high-priority log entry was made
@@ -71,8 +64,8 @@ to different locations (e.g. files, database, Slack, etc).
7164 channel can have its *own * handlers, which means you can store different log
7265 messages in different places. See:doc: `/logging/channels_handlers `.
7366
74- Symfony pre-configures some basic handlers in the`` config_dev.yml `` and `` config_prod.yml ``
75- files. Check these out for some real-world examples.
67+ Symfony pre-configures some basic handlers in thedefault `` monolog.yaml ``
68+ config files. Check these out for some real-world examples.
7669
7770This example uses *two * handlers: ``stream `` (to write to a file) and ``syslog ``
7871to write logs using the:phpfunction: `syslog ` function:
@@ -81,7 +74,7 @@ to write logs using the :phpfunction:`syslog` function:
8174
8275 ..code-block ::yaml
8376
84- # app/ config/config.yml
77+ # config/packages/monolog.yaml
8578monolog :
8679handlers :
8780# this "file_log" key could be anything
@@ -99,7 +92,7 @@ to write logs using the :phpfunction:`syslog` function:
9992
10093 ..code-block ::xml
10194
102- <!-- app/ config/config .xml-->
95+ <!-- config/packages/monolog .xml-->
10396 <?xml version =" 1.0" encoding =" UTF-8" ?>
10497 <container xmlns =" http://symfony.com/schema/dic/services"
10598xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -126,7 +119,7 @@ to write logs using the :phpfunction:`syslog` function:
126119
127120 ..code-block ::php
128121
129- //app/ config/config .php
122+ // config/packages/monolog .php
130123 $container->loadFromExtension('monolog', array(
131124 'handlers' => array(
132125 'file_log' => array(
@@ -157,7 +150,7 @@ one of the messages reaches an ``action_level``. Take this example:
157150
158151 ..code-block ::yaml
159152
160- # app/ config/config.yml
153+ # config/packages/monolog.yaml
161154monolog :
162155handlers :
163156filter_for_errors :
@@ -178,7 +171,7 @@ one of the messages reaches an ``action_level``. Take this example:
178171
179172 ..code-block ::xml
180173
181- <!-- app/ config/config .xml-->
174+ <!-- config/packages/monolog .xml-->
182175 <?xml version =" 1.0" encoding =" UTF-8" ?>
183176 <container xmlns =" http://symfony.com/schema/dic/services"
184177xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -211,7 +204,7 @@ one of the messages reaches an ``action_level``. Take this example:
211204
212205 ..code-block ::php
213206
214- //app/ config/config .php
207+ // config/packages/monolog .php
215208 $container->loadFromExtension('monolog', array(
216209 'handlers' => array(
217210 'filter_for_errors' => array(
@@ -271,7 +264,7 @@ option of your handler to ``rotating_file``:
271264
272265 ..code-block ::yaml
273266
274- # app/ config/config_dev.yml
267+ # config/packages/dev/monolog.yaml
275268monolog :
276269handlers :
277270main :
@@ -284,7 +277,7 @@ option of your handler to ``rotating_file``:
284277
285278 ..code-block ::xml
286279
287- <!-- app/ config/config_dev .xml-->
280+ <!-- config/packages/dev/monolog .xml-->
288281 <?xml version =" 1.0" encoding =" UTF-8" ?>
289282 <container xmlns =" http://symfony.com/schema/dic/services"
290283xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -308,7 +301,7 @@ option of your handler to ``rotating_file``:
308301
309302 ..code-block ::php
310303
311- //app/ config/config_dev .php
304+ // config/packages/dev/monolog .php
312305 $container->loadFromExtension('monolog', array(
313306 'handlers' => array(
314307 'main' => array(
@@ -325,8 +318,7 @@ option of your handler to ``rotating_file``:
325318 Using a Logger inside a Service
326319-------------------------------
327320
328- To use a logger in your own services, add the ``@logger `` service as an argument
329- of those services. If you want to use a pre-configured logger which uses a
321+ If you want to use in your own services a pre-configured logger which uses a
330322specific channel (``app `` by default), use the ``monolog.logger `` tag with the
331323``channel `` property as explained in the
332324:ref: `Dependency Injection reference <dic_tags-monolog >`.
@@ -344,9 +336,14 @@ Learn more
344336
345337..toctree ::
346338:maxdepth: 1
347- :glob:
348339
349- logging/*
340+ logging/monolog_regex_based_excludes
341+ logging/monolog_email
342+ logging/channels_handlers
343+ logging/monolog_console
344+ logging/disable_microsecond_precision
345+ logging/formatter
346+ logging/processors
350347
351348.. _Monolog :https://github.com/Seldaek/monolog
352349.. _LoggerInterface :https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php