sudhaus7 / logformatter
用于格式化和搜索TYPO3日志文件的命令行工具
Requires
- php: 7.2.*||7.3.*||7.4.*||8.0.*||8.1.*||8.2.*||8.3.*
- typo3/cms-core: 9.5.*||10.4.*||11.5.*||^12.4
Requires (Dev)
- friendsoftypo3/phpstan-typo3: *
- helhum/typo3-console: *
- ssch/typo3-rector: ^2.6
- typo3/cms-backend: ^12.0
- typo3/cms-frontend: ^12.0
- typo3/cms-install: ^12.0
- typo3/cms-lowlevel: ^12.0
- typo3/cms-tstemplate: ^12.0
- typo3/coding-standards: ^0.5.5
- vimeo/psalm: ^4.10
README
此扩展为 typo3 和 typo3cms 工具提供命令行工具,用于解析、搜索和格式化 TYPO3 日志文件。
部分内容已着色,日志记录器提供的信息将显示在表格中,堆栈跟踪已展开以供更好地阅读。此外,如果您的终端支持,堆栈跟踪中的文件名可以点击,并在您的编辑器中打开。
变更日志
1.5.1
- 添加了 ConsoleLogger 记录器。这基本上是 Symfony Console 记录器的副本,不同之处在于所有元数据都已展开,并且没有进行消息行替换 1.5.0
- 没有变化,只是标记为与 TYPO3 12 兼容
1.4.0
- 新功能:添加了通过请求将日志行添加到 TYPO3 日志中的功能,以记录当前的请求 URL
- 新功能:提供 LogProcessor 以将当前请求 URL 作为元数据添加到任意记录器配置
1.3.0
- 介绍环境变量 LOGFORMATTER_FILELINKFORMATTER、LOGFORMATTER_LINEFORMATTER、LOGFORMATTER_STACKTRACEPATTERN 和 LOGFORMATTER_LOGPATTERN
- 重新整理依赖注入以使用工厂和适当的 TYPO3 DI,而不是混乱的代码(感谢 Daniel Siepmann 在这个主题上的出色博客文章)
- 阐明 STDIN 选项的使用方法,以便与 tail -f 一起使用
- 代码风格清理
1.2.0 引入环境变量 LOGFORMATTER_MAX_BUFFER 以配置最大行缓冲区 (--max-buffer)
帮助
Description: Formats TYPO3 Logfiles Usage: logformatter [options] [--] [...] Arguments: file Filename or - for STDIN (for example with tail -f) Options: --search=SEARCH Search in message for this keyword --request=REQUEST display only this request --component=COMPONENT search within component --level=LEVEL show only this error level -m, --show-meta Show additional information / meta information -s, --show-stacktrace Show the stacktrace --hide-vendor Hide vendor paths in stacktrace, implies --show-stacktrace --pager (EXPERIMENTAL) paging --ignore-file-pattern[=IGNORE-FILE-PATTERN] Logfile filename patterns to ignore (Default typo3_deprecations*) (multiple values allowed) -h, --help Display help for the given command. When no command is given display help for the list command -q, --quiet Do not output any message -V, --version Display this application version --ansi|--no-ansi Force (or disable --no-ansi) ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: Parse, search, format and display TYPO3 Logfiles. It is possible to combine parameters. By default only the logline will be shown, the meta information and stacktrace will be hidden. Keywords can be searched and the output can be filtered by request, level and component. Usage: This will display all logs which are located in var/logs/ ./vendor/bin/typo3 logformatter In this example the output will be filtered according to a certain request ID ./vendor/bin/typo3 logformatter --request=928d81f2d604e In this example the output will be filtered according to a certain component ./vendor/bin/typo3 logformatter --component=TYPO3.CMS.Core.Error.ErrorHandler Filtering the output by error level ./vendor/bin/typo3 logformatter --level=WARNING Searching for a keyword, for example an Oops error code ./vendor/bin/typo3 logformatter --search=2021110100165236c2ab3f Displaying meta information given to the log by the process (will displayed in a table) ./vendor/bin/typo3 logformatter --show-meta ./vendor/bin/typo3 logformatter -m Displaying the stack-trace in an expanded, readable form (one line per stack) ./vendor/bin/typo3 logformatter --show-stacktrace ./vendor/bin/typo3 logformatter -s Skipping stacks pointing to /vendor in the stacktrace to shorten it ./vendor/bin/typo3 logformatter --show-stacktrace --hide-vendor Don't parse logfiles matching a certain file pattern (multiple) ./vendor/bin/typo3 logformatter --ignore-file-pattern="*def.log" Parsing a specific file ./vendor/bin/typo3 logformatter var/log/typo3_0fb8cbec8e.log Using stdin as input tail -f var/log/typo3_0fb8cbec8e.log | ./vendor/bin/typo3 logformatter -
示例输出
与 PHPStorm 一起使用
虽然 PHPStorm 会在您在堆栈跟踪中单击文件名时打开文件,但它不会跳转到该行。这可以通过注入不同的文件链接格式器来实现
这可以通过覆盖 Services.yaml 或简单地将以下行添加到您的 AdditionalConfiguration.php 中来完成
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['logformatter']['filelinkFormat'] = \Sudhaus7\Logformatter\Format\PhpstormlinkFormat::class;
现在链接将包含 phpstorm:// 命名空间,并打开文件并跳转到指定的行
使用环境变量或 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'] 选项
如前例所示,有一些配置选项和环境变量可用于修改和扩展日志格式化程序
LOGFORMATTER_MAX_BUFFER
此环境变量替代了参数 --max-buffer。如果您有大的堆栈跟踪,请使用此变量增加缓冲区。它接受一个整数,表示要读取的字节数。如果您缺少行或堆栈跟踪,请使用此变量
例如: export LOGFORMATTER_MAX_BUFFER=10000000
LOGFORMATTER_FILELINKFORMATTER
这与设置 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['logformatter']['filelinkFormat'] = \Sudhaus7\Logformatter\Format\PhpstormlinkFormat::class;
相同
此变量的表示法是点表示法
例如: export LOGFORMATTER_FILELINKFORMATTER=Sudhaus7.Logformatter.Format.PhpstormlinkFormat
这将更改堆栈跟踪中的链接的链接格式化程序
LOGFORMATTER_LINEFORMATTER
这与设置 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['logformatter']['format'] = \Sudhaus7\Logformatter\Format\LineFormat::class;
相同
此变量的表示法是点表示法
例如: export LOGFORMATTER_FILELINKFORMATTER=Sudhaus7.Logformatter.Format.LineFormat
(默认)
这指定了在输出中如何格式化日志行
LOGFORMATTER_LOGPATTERN
这与设置 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['logformatter']['pattern'] = \Sudhaus7\Logformatter\Pattern\Typo3LogPattern::class;
相同
此变量的表示法是点表示法
例如:export LOGFORMATTER_FILELINKFORMATTER=Sudhaus7.Logformatter.Pattern.Typo3LogPattern
(默认值)
这指定了如何解析日志行。通过更改此设置,可以解析除TYPO3格式以外的其他日志格式
LOGFORMATTER_LOGPATTERN
这与设置 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['logformatter']['stacktracePattern'] = \Sudhaus7\Logformatter\Pattern\StacktracePattern::class;
相同
此变量的表示法是点表示法
例如:export LOGFORMATTER_FILELINKFORMATTER=Sudhaus7.Logformatter.Pattern.StacktracePattern
(默认值)
这指定了如何解析堆栈跟踪。通过更改此设置,可以解析除TYPO3格式以外的其他格式
通常将请求URL添加到日志文件中
此功能将添加包含当前请求URL的日志行。这的优点是,当您使用--request=REQUEST选项搜索所有行以查找特定请求时,您将获得生成此特定请求的URL。这是获取一般信息或当您监控的不是特定日志条目,而是一般日志条目时的一种可能方法
要启用此功能,请在TYPO3后端扩展设置中的设置 -> 扩展配置 -> logformatter -> '启用中间件将请求URL按请求记录到TYPO3日志文件'中选中logrequesturl选项
或者
如果您已安装typo3cms CLI工具,请在项目根目录的shell中执行以下命令
./vendor/bin/typo3cms configuration:set EXTENSIONS/logformatter/logrequesturl 1
要禁用,请使用相同命令,并在末尾添加0
./vendor/bin/typo3cms configuration:set EXTENSIONS/logformatter/logrequesturl 0
使用日志处理器
如果您想使用此日志处理器来调试或监控特定的日志配置,将请求URL添加到特定日志条目的元信息可能比将URL作为单独的日志条目添加(前一条记录)更好。
要添加日志处理器,可以将以下内容添加到您的 AdditionConfiguration.php
$GLOBALS['TYPO3_CONF_VARS']['LOG']['EXAMPLE']['EXTENSION']['NAMESPACE']['CLASS']['processorConfiguration'] = [ \TYPO3\CMS\Core\Log\LogLevel::ERROR => [ \Sudhaus7\Logformatter\Log\Processor\UrlProcessor::class => [] ], ];
配置类似于初始writerConfiguration。另请参阅官方文档