Skip to content

Commit 21215ea

Browse files
committed
minor #10321 Minimalist default PSR-3 logger (dunglas)
This PR was squashed before being merged into the 3.4 branch (closes #10321). Discussion ---------- Minimalist default PSR-3 logger symfony/symfony#24300 Commits ------- da84567 Minimalist default PSR-3 logger
2 parents 400084e + da84567 commit 21215ea

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

logging.rst

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
Logging with Monolog
2-
====================
1+
Logging
2+
=======
33

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>`.
622

723
Logging a Message
824
-----------------
925

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::
1227

1328
use Psr\Log\LoggerInterface;
1429

@@ -29,11 +44,26 @@ your controller::
2944
}
3045

3146
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-
3547
See LoggerInterface_ for a list of all of the methods on the logger.
3648

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+
3767
Where Logs are Stored
3868
---------------------
3969

@@ -338,6 +368,9 @@ Learn more
338368

339369
logging/*
340370

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)
341374
.. _Monolog: https://github.com/Seldaek/monolog
342375
.. _LoggerInterface: https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php
343376
.. _`logrotate`: https://github.com/logrotate/logrotate

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy