Make it easier to use different log formats
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
- [ ] Functional review done
- [ ] Potential edge cases thought about (behavior of the code with strange input, with strange internal state or possible interactions with other Matomo subsystems)
- [ ] Usability review done (is anything maybe unclear or think about anything that would cause people to reach out to support)
- [ ] Security review done
- [ ] Wording review done
- [ ] Code review done
- [ ] Tests were added if useful/possible
- [ ] Reviewed for breaking changes
- [ ] Developer changelog updated if needed
- [ ] Documentation added if needed
- [ ] Existing documentation updated if needed
@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?
If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.
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
If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.
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
If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.
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
If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.