From 46a95bf71deaa535eb80936788ed2575a971f909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 10 Sep 2018 23:48:21 +0200 Subject: [PATCH 1/4] Minimalist default PSR-3 logger --- logging.rst | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/logging.rst b/logging.rst index f0ea2c248ca..d1cb49e223d 100644 --- a/logging.rst +++ b/logging.rst @@ -1,14 +1,28 @@ -Logging with Monolog -==================== +Logging +======= -Symfony comes with an outside library - called Monolog_ - that allows you to create -logs that can be stored in a variety of different places. +Symfony comes with a minimalist `PSR-3`_ logger: :class:`Symfony\Component\HttpKernel\Log\Logger`. +In conformance with `the twelve-factor app methodology`_, it sends messages starting from the +``WARNING`` level to `stderr`_. + +The minimal log level can be changed by setting the ``SHELL_VERBOSITY`` environment variable: + +========================= ================= +``SHELL_VERBOSITY`` value Minimum log level +========================= ================= +``-1`` ``ERROR`` +``1`` ``NOTICE`` +``2`` ``INFO`` +``3`` ``DEBUG`` + +The minimum log level, the default output and the log format can also be changed by +passing the appropriate arguments to the constructor of :class:`Symfony\Component\HttpKernel\Log\Logger`. +To do so, :ref:`override the ``logger`` service definition `. Logging a Message ----------------- -To log a message, fetch the ``logger`` service from the container in -your controller:: +To log a message, inject the default logger in your controller:: use Psr\Log\LoggerInterface; @@ -29,11 +43,26 @@ your controller:: } The ``logger`` service has different methods for different logging levels/priorities. -You can configure the logger to do different things based on the *level* of a message -(e.g. :doc:`send an email when an error occurs `). - See LoggerInterface_ for a list of all of the methods on the logger. +Monolog +------- + +Symfony integrates seamlessly with `Monolog`_, the most popular PHP logging +library, to create and store log messages in a variety of different places +and trigger various actions. + +For instance, using Monolog you can configure the logger to do different things based on the +*level* of a message (e.g. :doc:`send an email when an error occurs `). + +Run this command to install the Monolog based logger before using it: + +.. code-block:: terminal + + $ composer require symfony/monolog-bundle + +The following sections assume that Monolog is installed. + Where Logs are Stored --------------------- @@ -338,6 +367,9 @@ Learn more logging/* +.. _`the twelve-factor app methodology`: https://12factor.net/logs +.. _PSR-3: https://www.php-fig.org/psr/psr-3/ +.. _`stderr`: https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr) .. _Monolog: https://github.com/Seldaek/monolog .. _LoggerInterface: https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php .. _`logrotate`: https://github.com/logrotate/logrotate From 915a50b314b899227ace651b16b3ea2e68572802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 11 Sep 2018 00:29:54 +0200 Subject: [PATCH 2/4] RST --- logging.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logging.rst b/logging.rst index d1cb49e223d..d235e119764 100644 --- a/logging.rst +++ b/logging.rst @@ -1,7 +1,7 @@ Logging ======= -Symfony comes with a minimalist `PSR-3`_ logger: :class:`Symfony\Component\HttpKernel\Log\Logger`. +Symfony comes with a minimalist `PSR-3`_ logger: :class:`Symfony\\Component\\HttpKernel\\Log\\Logger`. In conformance with `the twelve-factor app methodology`_, it sends messages starting from the ``WARNING`` level to `stderr`_. @@ -16,7 +16,7 @@ The minimal log level can be changed by setting the ``SHELL_VERBOSITY`` environm ``3`` ``DEBUG`` The minimum log level, the default output and the log format can also be changed by -passing the appropriate arguments to the constructor of :class:`Symfony\Component\HttpKernel\Log\Logger`. +passing the appropriate arguments to the constructor of :class:`Symfony\\Component\\HttpKernel\\Log\\Logger`. To do so, :ref:`override the ``logger`` service definition `. Logging a Message From 6dec631e8b8c865629a4c2e4b721677483854297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 11 Sep 2018 00:36:32 +0200 Subject: [PATCH 3/4] RST --- logging.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/logging.rst b/logging.rst index d235e119764..f6c97d3a32e 100644 --- a/logging.rst +++ b/logging.rst @@ -14,6 +14,7 @@ The minimal log level can be changed by setting the ``SHELL_VERBOSITY`` environm ``1`` ``NOTICE`` ``2`` ``INFO`` ``3`` ``DEBUG`` +========================= ================= The minimum log level, the default output and the log format can also be changed by passing the appropriate arguments to the constructor of :class:`Symfony\\Component\\HttpKernel\\Log\\Logger`. From b59a999dcaa932226d328031fba397d3653e0db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 11 Sep 2018 00:41:54 +0200 Subject: [PATCH 4/4] rst --- logging.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logging.rst b/logging.rst index f6c97d3a32e..56a3675bc44 100644 --- a/logging.rst +++ b/logging.rst @@ -18,7 +18,7 @@ The minimal log level can be changed by setting the ``SHELL_VERBOSITY`` environm The minimum log level, the default output and the log format can also be changed by passing the appropriate arguments to the constructor of :class:`Symfony\\Component\\HttpKernel\\Log\\Logger`. -To do so, :ref:`override the ``logger`` service definition `. +To do so, :ref:`override the "logger" service definition `. Logging a Message -----------------