Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logger] [Logging] Add references to the ConsoleLogger #20583

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions logging.rst
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 <service-psr4-loader>`.
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 <service-psr4-loader>`.

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;
// ...
Expand Down Expand Up @@ -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
Expand Down
Loading