From b9c7139364f16c941099891df800930c1dfd724f Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Sat, 18 Jan 2025 02:05:12 -0300 Subject: [PATCH 1/2] [Logging] Add references to the `ConsoleLogger` --- logging.rst | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/logging.rst b/logging.rst index c66312f88f9..0aabf9c7c5f 100644 --- a/logging.rst +++ b/logging.rst @@ -1,8 +1,10 @@ Logging ======= -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 +Symfony comes with two minimalist `PSR-3`_ loggers: :class:`Symfony\\Component\\HttpKernel\\Log\\Logger` +for the HTTP context and :class:`Symfony\\Component\\Console\\Logger\\ConsoleLogger` for the +CLI context. +In conformance with `the twelve-factor app methodology`_, they send messages starting from the ``WARNING`` level to `stderr`_. The minimal log level can be changed by setting the ``SHELL_VERBOSITY`` environment variable: @@ -17,13 +19,18 @@ 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 `. +passing the appropriate arguments to the constructor of :class:`Symfony\\Component\\HttpKernel\\Log\\Logger` +and :class:`Symfony\\Component\\Console\\Logger\\ConsoleLogger`. + +The :class:`Symfony\\Component\\HttpKernel\\Log\\Logger` class is available through the ``logger`` service. +To pass your configuration, you can :ref:`override the "logger" service definition `. + +For more information about ``ConsoleLogger``, see :doc:`/components/console/logger`. Logging a Message ----------------- -To log a message, inject the default logger in your controller or service:: +To log a message using the ``logger`` service, inject the default logger in your controller or service:: use Psr\Log\LoggerInterface; // ... @@ -55,7 +62,7 @@ Adding placeholders to log messages is recommended because: * It's better for security, because escaping can then be done by the implementation in a context-aware fashion. -The ``logger`` service has different methods for different logging levels/priorities. +The logger implementations has different methods for different logging levels/priorities. See `LoggerInterface`_ for a list of all of the methods on the logger. Monolog From fa4563353e498b9a6dc3ce20c3043f720fe1493e Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 22 Jan 2025 10:29:43 +0100 Subject: [PATCH 2/2] Minor tweaks --- logging.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/logging.rst b/logging.rst index 0aabf9c7c5f..0ad36031dd5 100644 --- a/logging.rst +++ b/logging.rst @@ -3,9 +3,8 @@ Logging Symfony comes with two minimalist `PSR-3`_ loggers: :class:`Symfony\\Component\\HttpKernel\\Log\\Logger` for the HTTP context and :class:`Symfony\\Component\\Console\\Logger\\ConsoleLogger` for the -CLI context. -In conformance with `the twelve-factor app methodology`_, they send messages starting from the -``WARNING`` level to `stderr`_. +CLI context. In conformance with `the twelve-factor app methodology`_, they send messages +starting from the ``WARNING`` level to `stderr`_. The minimal log level can be changed by setting the ``SHELL_VERBOSITY`` environment variable: @@ -30,7 +29,7 @@ For more information about ``ConsoleLogger``, see :doc:`/components/console/logg Logging a Message ----------------- -To log a message using the ``logger`` service, inject the default logger in your controller or service:: +To log a message, inject the default logger in your controller or service:: use Psr\Log\LoggerInterface; // ... @@ -62,7 +61,7 @@ Adding placeholders to log messages is recommended because: * It's better for security, because escaping can then be done by the implementation in a context-aware fashion. -The logger implementations has different methods for different logging levels/priorities. +The ``logger`` service has different methods for different logging levels/priorities. See `LoggerInterface`_ for a list of all of the methods on the logger. Monolog