Feature #82483

PSR logger improvement

Added by Artur Cichosz almost 2 years ago. Updated almost 2 years ago.

Should have
Target version:
Start date:
Due date:
% Done:


PHP Version:
logger writer
Sprint Focus:


I am just confused about this statement from the official logger documentation:

"An early return in the log() method prevents unneeded computation work to be done. So you are safe to call $logger->debug() frequently without slowing down your code too much. The Logger will know by its configuration, what the most explicit severity level is." https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Logging/Logger/Index.html

Reading this I assumed, that the logger can get configured for a "log verbosity level", e.g. by means of $GLOBALS["TYPO3_CONF_VARS"]['SYS']['systemLogLevel'].
This way I would be able to put 1000 ->debug() calls in my code "without slowing down my code too much", because all records for records above this setting would get skipped. But this is clearly not the case. The default log writer (typo3temp/logs/typo3.log) which logs all the log entries no matter what log level they are.

But e.g. on production it clearly isn't necessary, so how should we understand the cited statement from documentation above?
I know I can explicitely disable the default logger probably by means of TYPO3 environment/context etc. but stil, it is confusing and not documented.

I work on a project using TYPO3 6.2 LTS now, so maybe there is some undocumented imporvements in later versions, I do not know.

So I got inspired by symfonys/monologs "fingers_crossed" handler/writer and added this (class file attached to this issue) alternative for the default FileWriter to a project, which stores all records in memory first and writes them to the file only then, when at least some verbosity threshold (e.g. ERROR) has been hit during the entire request. This threshold could be set explicitely to a higher level by means of e.g. $GLOBALS["TYPO3_CONF_VARS"]['SYS']['systemLogLevel'].

May be somethig like this may be worth putting it into core?

To overwrite the default handler config I used this then:

 * Reconfigure the default log writer to use our own log file writer which stores all recieved log records
 * and writes them to a file only if a certain severity level record has been hit during this request.
 * The maximum severity log level can be set using $GLOBALS["TYPO3_CONF_VARS"]['SYS']['systemLogLevel']
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = array(
    \TYPO3\CMS\Core\Log\LogLevel::DEBUG => array(
       // add a FileWriter
        'Q3i\\T3Local\\Core\\Log\\Writer\\FingersCrossedFileWriter' => array(
           // configuration for the writer
            'logFile' => 'typo3temp/logs/typo3.log'

FingersCrossedFileWriter.php View (2.22 KB) Artur Cichosz, 2017-09-14 10:59

Related issues

Related to TYPO3 Core - Feature #85506: Replace logging framework with monolog New 2018-07-07


#1 Updated by Artur Cichosz almost 2 years ago

  • Description updated (diff)

#2 Updated by Georg Ringer almost 2 years ago

  • Target version deleted (Candidate for Major Version)

Currently the whole logging is being changed in the core. The goal for 9 LTS is having monolog integrated where all those things are available. Until then you can use my monolog extension to have that available as well. composer is required for that (github.com/georgringer/monolog)

#3 Updated by Alexander Schnitzler 12 months ago

  • Related to Feature #85506: Replace logging framework with monolog added

Also available in: Atom PDF