@@ -7,19 +7,16 @@ logs that can be stored in a variety of different places.
77Logging a Message
88-----------------
99
10- To log a message, fetch the `` logger `` service from the container in
11- your controller ::
10+ If the application uses the :ref: ` default services.yaml configuration < service- container-services-load-example >`,
11+ you can get the logger service injecting the `` LoggerInterface `` class ::
1212
1313 use Psr\Log\LoggerInterface;
1414
15- public function indexAction (LoggerInterface $logger)
15+ public function index (LoggerInterface $logger)
1616 {
17- // alternative way of getting the logger
18- // $logger = $this->get('logger');
19-
2017 $logger->info('I just got the logger');
2118 $logger->error('An error occurred');
22-
19+
2320 $logger->critical('I left the oven on!', array(
2421 // include extra "context" info in your logs
2522 'cause' => 'in_hurry',
@@ -28,7 +25,7 @@ your controller::
2825 // ...
2926 }
3027
31- The `` logger `` service has different methods for different logging levels/priorities.
28+ The logger service has different methods for different logging levels/priorities.
3229You can configure the logger to do different things based on the *level * of a message
3330(e.g. :doc: `send an email when an error occurs </logging/monolog_email >`).
3431
@@ -37,10 +34,6 @@ See LoggerInterface_ for a list of all of the methods on the logger.
3734Where Logs are Stored
3835---------------------
3936
40- The configuration for *where * logs are stored lives in the specific
41- :doc: `environment </configuration/environments >` configuration files: ``config_dev.yml ``
42- and ``config_prod.yml ``.
43-
4437By default, log entries are written to the ``var/log/dev.log `` file when you're in
4538the ``dev `` environment. In the ``prod `` environment, logs are written to ``var/log/prod.log ``,
4639but *only * during a request where an error or high-priority log entry was made
@@ -61,8 +54,8 @@ to different locations (e.g. files, database, Slack, etc).
6154 channel can have its *own * handlers, which means you can store different log
6255 messages in different places. See :doc: `/logging/channels_handlers `.
6356
64- Symfony pre-configures some basic handlers in the `` config_dev.yml `` and `` config_prod.yml ``
65- files. Check these out for some real-world examples.
57+ Symfony pre-configures some basic handlers in the default `` monolog.yaml ``
58+ config files. Check these out for some real-world examples.
6659
6760This example uses *two * handlers: ``stream `` (to write to a file) and ``syslog ``
6861to write logs using the :phpfunction: `syslog ` function:
@@ -71,7 +64,7 @@ to write logs using the :phpfunction:`syslog` function:
7164
7265 .. code-block :: yaml
7366
74- # app/ config/config.yml
67+ # config/packcages/monolog.yaml
7568 monolog :
7669 handlers :
7770 # this "file_log" key could be anything
@@ -89,7 +82,7 @@ to write logs using the :phpfunction:`syslog` function:
8982
9083 .. code-block :: xml
9184
92- <!-- app/ config/config .xml -->
85+ <!-- config/packcages/monolog .xml -->
9386 <?xml version =" 1.0" encoding =" UTF-8" ?>
9487 <container xmlns =" http://symfony.com/schema/dic/services"
9588 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -116,7 +109,7 @@ to write logs using the :phpfunction:`syslog` function:
116109
117110 .. code-block :: php
118111
119- // app/ config/config .php
112+ // config/packcages/monolog .php
120113 $container->loadFromExtension('monolog', array(
121114 'handlers' => array(
122115 'file_log' => array(
@@ -147,7 +140,7 @@ one of the messages reaches an ``action_level``. Take this example:
147140
148141 .. code-block :: yaml
149142
150- # app/ config/config.yml
143+ # config/packcages/monolog.yaml
151144 monolog :
152145 handlers :
153146 filter_for_errors :
@@ -168,7 +161,7 @@ one of the messages reaches an ``action_level``. Take this example:
168161
169162 .. code-block :: xml
170163
171- <!-- app/ config/config .xml -->
164+ <!-- config/packcages/monolog .xml -->
172165 <?xml version =" 1.0" encoding =" UTF-8" ?>
173166 <container xmlns =" http://symfony.com/schema/dic/services"
174167 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -201,7 +194,7 @@ one of the messages reaches an ``action_level``. Take this example:
201194
202195 .. code-block :: php
203196
204- // app/ config/config .php
197+ // config/packcages/monolog .php
205198 $container->loadFromExtension('monolog', array(
206199 'handlers' => array(
207200 'filter_for_errors' => array(
@@ -261,7 +254,7 @@ option of your handler to ``rotating_file``:
261254
262255 .. code-block :: yaml
263256
264- # app/ config/config_dev.yml
257+ # config/packcages/dev/monolog.yaml
265258 monolog :
266259 handlers :
267260 main :
@@ -274,7 +267,7 @@ option of your handler to ``rotating_file``:
274267
275268 .. code-block :: xml
276269
277- <!-- app/ config/config_dev .xml -->
270+ <!-- config/packcages/dev/monolog .xml -->
278271 <?xml version =" 1.0" encoding =" UTF-8" ?>
279272 <container xmlns =" http://symfony.com/schema/dic/services"
280273 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -298,7 +291,7 @@ option of your handler to ``rotating_file``:
298291
299292 .. code-block :: php
300293
301- // app/ config/config_dev .php
294+ // config/packcages/dev/monolog .php
302295 $container->loadFromExtension('monolog', array(
303296 'handlers' => array(
304297 'main' => array(
@@ -315,8 +308,7 @@ option of your handler to ``rotating_file``:
315308 Using a Logger inside a Service
316309-------------------------------
317310
318- To use a logger in your own services, add the ``@logger `` service as an argument
319- of those services. If you want to use a pre-configured logger which uses a
311+ If you want to use in your own services a pre-configured logger which uses a
320312specific channel (``app `` by default), use the ``monolog.logger `` tag with the
321313``channel `` property as explained in the
322314:ref: `Dependency Injection reference <dic_tags-monolog >`.
@@ -334,9 +326,14 @@ Learn more
334326
335327.. toctree ::
336328 :maxdepth: 1
337- :glob:
338329
339- logging/*
330+ logging/monolog_regex_based_excludes
331+ logging/monolog_email
332+ logging/channels_handlers
333+ logging/monolog_console
334+ logging/disable_microsecond_precision
335+ logging/formatter
336+ logging/processors
340337
341338.. _Monolog : https://github.com/Seldaek/monolog
342339.. _LoggerInterface : https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php
0 commit comments