1
- Logging with Monolog
2
- ====================
1
+ Logging
2
+ =======
3
3
4
- Symfony comes with an outside library - called Monolog _ - that allows you to create
5
- logs that can be stored in a variety of different places.
4
+ Symfony comes with a minimalist `PSR-3 `_ logger: :class: `Symfony\\ Component\\ HttpKernel\\ Log\\ Logger `.
5
+ In conformance with `the twelve-factor app methodology `_, it sends messages starting from the
6
+ ``WARNING `` level to `stderr `_.
7
+
8
+ The minimal log level can be changed by setting the ``SHELL_VERBOSITY `` environment variable:
9
+
10
+ ========================= =================
11
+ ``SHELL_VERBOSITY `` value Minimum log level
12
+ ========================= =================
13
+ ``-1 `` ``ERROR ``
14
+ ``1 `` ``NOTICE ``
15
+ ``2 `` ``INFO ``
16
+ ``3 `` ``DEBUG ``
17
+ ========================= =================
18
+
19
+ The minimum log level, the default output and the log format can also be changed by
20
+ passing the appropriate arguments to the constructor of :class: `Symfony\\ Component\\ HttpKernel\\ Log\\ Logger `.
21
+ To do so, :ref: `override the "logger" service definition <service-psr4-loader >`.
6
22
7
23
Logging a Message
8
24
-----------------
9
25
10
- To log a message, fetch the ``logger `` service from the container in
11
- your controller::
26
+ To log a message, inject the default logger in your controller::
12
27
13
28
use Psr\Log\LoggerInterface;
14
29
@@ -29,11 +44,26 @@ your controller::
29
44
}
30
45
31
46
The ``logger `` service has different methods for different logging levels/priorities.
32
- You can configure the logger to do different things based on the *level * of a message
33
- (e.g. :doc: `send an email when an error occurs </logging/monolog_email >`).
34
-
35
47
See LoggerInterface _ for a list of all of the methods on the logger.
36
48
49
+ Monolog
50
+ -------
51
+
52
+ Symfony integrates seamlessly with `Monolog `_, the most popular PHP logging
53
+ library, to create and store log messages in a variety of different places
54
+ and trigger various actions.
55
+
56
+ For instance, using Monolog you can configure the logger to do different things based on the
57
+ *level * of a message (e.g. :doc: `send an email when an error occurs </logging/monolog_email >`).
58
+
59
+ Run this command to install the Monolog based logger before using it:
60
+
61
+ .. code-block :: terminal
62
+
63
+ $ composer require symfony/monolog-bundle
64
+
65
+ The following sections assume that Monolog is installed.
66
+
37
67
Where Logs are Stored
38
68
---------------------
39
69
@@ -338,6 +368,9 @@ Learn more
338
368
339
369
logging/*
340
370
371
+ .. _`the twelve-factor app methodology` : https://12factor.net/logs
372
+ .. _PSR-3 : https://www.php-fig.org/psr/psr-3/
373
+ .. _`stderr` : https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)
341
374
.. _Monolog : https://github.com/Seldaek/monolog
342
375
.. _LoggerInterface : https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php
343
376
.. _`logrotate` : https://github.com/logrotate/logrotate
0 commit comments