Project

General

Profile

Feature #82483

Updated by Artur Cichosz over 6 years ago

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: 

 <pre> 
 /** @/** 
  * 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' 
         ) 
     ) 
 ); 
 </pre> );@ 

Back