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 #1

Updated by Artur Cichosz over 6 years ago

  • Description updated (diff)
Actions #2

Updated by Georg Ringer over 6 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)

Actions #3

Updated by Alexander Schnitzler almost 6 years ago

  • Related to Feature #85506: Integrate monolog as logging framework added
Actions #4

Updated by Susanne Moog about 4 years ago

  • Subject changed from PSR logger improvement to Introduce FingersCrossed LogWriter
  • Status changed from New to Accepted

I like the idea of such a writer. If and when we integrate monolog this would probably be solved automatically, however, as we have seen that is quite the task so it might make sense to implement such a writer independent of monolog.

Actions #5

Updated by Christian Kuhn almost 3 years ago

Actions #6

Updated by Christian Kuhn almost 3 years ago

  • Status changed from Accepted to Closed

Closing here for now, to keep some kind of overview:

I agree we should have something like that. We restarted PSR-3 topic and monolog with epic #94356 - if we finish this, a fingers crossed writer may come automatically.

Actions #7

Updated by Christian Kuhn almost 3 years ago

  • Related to deleted (Feature #85506: Integrate monolog as logging framework)
Actions

Also available in: Atom PDF