matomo icon indicating copy to clipboard operation
matomo copied to clipboard

Make it easier to use different log formats

Open sgiehl opened this issue 9 months ago • 8 comments

Description:

Currently Matomo by default writes text messages to log handlers. While it is already possible to change the log format to something like json using custom DI config, this PR aims to make it easier, by providing the possibility to define the desired log format in the ini config.

https://github.com/matomo-org/matomo/blob/409c5eb9dfdb7b47798357bc283c8be74fb920bc/config/global.ini.php#L132-L135

While the screen log writer will always use text, the config allows to set the format for all other formats or specific formats only.

Supported formats are now text, json. loggly and logstash. If requested, we could also add other formats supported by Monolog.

Further adjustments to the logging can still be done by providing some DI config, like overwriting constructor parameters, adding new log processors or similar.

A simple example how to add context or additional values being logged would be something like this in config.php file:

return [
    'log.processors' => Piwik\DI::add([
        new class ()
        {
            public function __invoke(array $record)
            {
                $record['custom_filed'] = 'value';
                return $record;
            }
        }
    ]),
];

replaces #22994

Review

sgiehl avatar Mar 24 '25 15:03 sgiehl

@sgiehl just tested it out and got json logs to file working :partying_face:

However json logs do not appear correctly in the LogViewer plugin. I presume thsi will need to be addressed in the logviewer code with a separate pr? image

krezreb avatar Mar 25 '25 09:03 krezreb

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

github-actions[bot] avatar Apr 11 '25 02:04 github-actions[bot]

This PR was last updated more than one month ago, maybe it's time to close it. Please check if there is anything we still can do or close this PR. ping @matomo-org/core-reviewers

github-actions[bot] avatar May 23 '25 02:05 github-actions[bot]

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

github-actions[bot] avatar Jun 07 '25 02:06 github-actions[bot]

This PR was last updated more than one month ago, maybe it's time to close it. Please check if there is anything we still can do or close this PR. ping @matomo-org/core-reviewers

github-actions[bot] avatar Jul 20 '25 02:07 github-actions[bot]

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

github-actions[bot] avatar Aug 04 '25 02:08 github-actions[bot]

This PR was last updated more than one month ago, maybe it's time to close it. Please check if there is anything we still can do or close this PR. ping @matomo-org/core-reviewers

github-actions[bot] avatar Sep 16 '25 02:09 github-actions[bot]

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

github-actions[bot] avatar Nov 21 '25 02:11 github-actions[bot]