From 6141e0211e764dd1f1b6ea3026d6908a7a54e2aa Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 14 Mar 2024 16:59:04 +0100 Subject: [PATCH] [Logger] Using LogLevel `const`s, Part 2 Page: https://symfony.com/doc/5.x/logging.html Remaining occurrences, as ancounced in https://github.com/symfony/symfony-docs/pull/19670 --- logging.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/logging.rst b/logging.rst index 8b26cda9796..978bd57da28 100644 --- a/logging.rst +++ b/logging.rst @@ -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') @@ -254,13 +254,14 @@ 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') ; @@ -268,17 +269,17 @@ one of the messages reaches an ``action_level``. Take this example: $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! @@ -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);