Skip to content

[Logger] Using LogLevel consts, Part 2 #19672

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

Merged
merged 1 commit into from
Mar 15, 2024
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
14 changes: 8 additions & 6 deletions logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ to write logs using the :phpfunction:`syslog` function:
->type('stream')
// log to var/logs/(environment).log
->path('%kernel.logs_dir%/%kernel.environment%.log')
// log *all* messages (debug is lowest level)
// log *all* messages (LogLevel::DEBUG is lowest level)
->level(LogLevel::DEBUG);

$monolog->handler('syslog_handler')
Expand Down Expand Up @@ -254,31 +254,32 @@ one of the messages reaches an ``action_level``. Take this example:
.. code-block:: php

// config/packages/prod/monolog.php
use Psr\Log\LogLevel;
use Symfony\Config\MonologConfig;

return static function (MonologConfig $monolog) {
$monolog->handler('filter_for_errors')
->type('fingers_crossed')
// if *one* log is error or higher, pass *all* to file_log
->actionLevel('error')
->actionLevel(LogLevel::ERROR)
->handler('file_log')
;

// now passed *all* logs, but only if one log is error or higher
$monolog->handler('file_log')
->type('stream')
->path('%kernel.logs_dir%/%kernel.environment%.log')
->level('debug')
->level(LogLevel::DEBUG)
;

// still passed *all* logs, and still only logs error or higher
$monolog->handler('syslog_handler')
->type('syslog')
->level('error')
->level(LogLevel::ERROR)
;
};

Now, if even one log entry has an ``error`` level or higher, then *all* log entries
Now, if even one log entry has an ``LogLevel::ERROR`` level or higher, then *all* log entries
for that request are saved to a file via the ``file_log`` handler. That means that
your log file will contain *all* the details about the problematic request - making
debugging much easier!
Expand Down Expand Up @@ -349,13 +350,14 @@ option of your handler to ``rotating_file``:
.. code-block:: php

// config/packages/prod/monolog.php
use Psr\Log\LogLevel;
use Symfony\Config\MonologConfig;

return static function (MonologConfig $monolog) {
$monolog->handler('main')
->type('rotating_file')
->path('%kernel.logs_dir%/%kernel.environment%.log')
->level('debug')
->level(LogLevel::DEBUG)
// max number of log files to keep
// defaults to zero, which means infinite files
->maxFiles(10);
Expand Down