rsg/log

RSG 的日志工具

v0.1.3 2021-04-16 12:39 UTC

This package is not auto-updated.

Last update: 2024-09-28 05:20:58 UTC


README

RSG 可以使用的日志工具集合。

处理器

StandardProcessor

这是根处理器。它不会装饰其他 ProcessorInterfaces,如本库中的其他处理器。它用于添加所有记录都应该包含的值。

用法

Rsg\Log\StandardProcessor:
    tags: [ 'monolog.processor' ]
    arguments: [ '%env%', 'some-service' ]

WebProcessor

Monolog 的 WebProcessor 的适配器。它用于为网络请求添加“额外”数据。这也会装饰任何 ProcessorInterface。

用法

Rsg\Log\StandardProcessor:
    arguments: [ '%env%', 'some-service' ]

Rsg\Log\WebProcessor:
    tags: [ 'monolog.processor' ]
    arguments: [ '@Rsg\Log\StandardProcessor' ]

ContextProcessor

从上下文中复制重要数据到记录的根。这也会装饰任何 ProcessorInterface。目的是允许我们执行类似 $logger->info( 'some message', [ 'important_field' => 1 ] ); 的操作,并能够在我们的日志聚合器中搜索 "important_field=1"。

用法

Rsg\Log\StandardProcessor:
    arguments: [ '%env%', 'some-service' ]

Rsg\Log\ContextProcessor:
    tags: [ 'monolog.processor' ]
    arguments: [ '@Rsg\Log\StandardProcessor' ]

此外,还可以自定义要复制的键。

Rsg\Log\StandardProcessor:
    arguments: [ '%env%', 'some-service' ]

Rsg\Log\ContextProcessor:
    tags: [ 'monolog.processor' ]
    arguments:
        $processor: '@Rsg\Log\StandardProcessor'
        $keys_to_escalate:
            - foo
            - bar
            - baz

推荐设置

所有 RSG 应用程序推荐的设置应包括

monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: error
            passthru_level: info
            handler: nested
            formatter: monolog.formatter

monolog.formatter:
    class: 'Monolog\Formatter\JsonFormatter'