ssch / t3-psr3-log-processor

提供 PSR-3 交插日志处理器

v1.0.0 2023-03-16 22:19 UTC

README

https://www.php-fig.org/psr/psr-3/#12-message

集成指南

该扩展附带一个自定义处理器,用于将日志消息中的上下文变量替换为消息。假设您有一个以下格式的日志消息

use Psr\Log\LogLevel;use TYPO3\CMS\Core\Log\LogRecord;

$logRecord = new LogRecord('foo', LogLevel::INFO, 'A message with a {placeholder}', ['placeholder' => 'bar']);

在这种情况下,消息的 {占位符} 将在扩展提供的 PsrLogProcessor 处理时被 "bar" 替换。

为了激活处理器,您可以通过 ext_localconf.php 进行配置,例如

$GLOBALS['TYPO3_CONF_VARS']['LOG']['Documentation']['Examples']['Controller']['processorConfiguration'] = [
    // configuration for Debug level log entries and above
    \TYPO3\CMS\Core\Log\LogLevel::DEBUG => [
        \Ssch\Psr3LogProcessor\Processor\PsrLogMessageProcessor::class => [
            // The format of the timestamp: one supported by DateTime::format
            'dateFormat' => DateTime::ISO8601,
            // If set to true the fields interpolated into message gets unset
            'removeUsedContextFields' => true,
            // Arrays will be json encoded. With this option you can define how this will happen
            'jsonFlags' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
        ]
    ]
];

https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Logging/Configuration/Index.html#processor-configuration

致谢

此日志处理器深受 monolog/monolog 处理器的影响。