Project

General

Profile

Actions

Feature #82483

closed

Introduce FingersCrossed LogWriter

Added by Artur Cichosz over 6 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Logging
Target version:
-
Start date:
2017-09-14
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
logger writer
Complexity:
Sprint Focus:

Description

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'
        )
    )
);

Files

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

Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Epic #94356: Embrace PSR-3Closed2021-06-11

Actions
Actions

Also available in: Atom PDF