hedii / laravel-gelf-logger

A package to send gelf logs to a gelf compatible backend like graylog
MIT License
125 stars 33 forks source link

Laravel 10 compatibility processor configurations #49

Open mvsvolkov opened 9 months ago

mvsvolkov commented 9 months ago

Adding Laravel 10 compatibility for logger processors configuration

https://laravel.com/docs/10.x/logging#monolog-processors

Original code can by found here:

https://github.com/illuminate/log/blob/cf040cfddc30d5746554f173fc9c1f535077af45/LogManager.php#L409

hedii commented 9 months ago

Hello, thanks for this PR.

Can you explain briefly what is the purpose of the options (with) when configuring processors?

Maybe you can share a Processor you are using with my package that can benefit from defining options?

mvsvolkov commented 9 months ago

Hello, thanks for this PR.

Can you explain briefly what is the purpose of the options (with) when configuring processors?

Maybe you can share a Processor you are using with my package that can benefit from defining options?

Hello, this is a parameters for Processor construct method.

For example https://github.com/Seldaek/monolog/blob/main/src/Monolog/Processor/MemoryProcessor.php this processor have two options, and with with config, you can override them

[
    'processor' => Monolog\Processor\MemoryUsageProcessor::class,
    'with' => ['useFormatting' => env('USE_FORMATTING_MEMORY', false)]
]

In our cases Graylog has limitation for context item size, we have to split it into the chunks to avoid missed message parts. We use constructor parameters to define size of this chunks

'processors' => [
        ...,
        [
            'processor' => GraylogContextFragmentationProcessor::class,
            'with' => [
                'contextChunkSize' => env('GRAYLOG_CONTEXT_CHUNK_SIZE', 25),
            ],
        ],
    ],
hedii commented 9 months ago

Ok thanks.

Can I see your GraylogContextFragmentationProcessor::class to fully understand and write a test for this new feature?

mvsvolkov commented 9 months ago

Ok thanks.

Can I see your GraylogContextFragmentationProcessor::class to fully understand and write a test for this new feature?

This class has a lot of project specific code =)

For example, i add feature to existing RequestIdProcessor, for change recorder field name, and add test to it.

[
    'processor' => \Hedii\LaravelGelfLogger\Processors\RenameIdFieldProcessor::class,
    'with' => [
        'fieldName' => '_other_id',
    ],
],