We would like to centralize logs with our Matomo instance in an ELK stack. I’ve been told it would be better for indexation if Matomo logs could be in json format.
From what I’ve seen Matomo use Monolog to output log, is there a way to config Matomo to use jsonFormatter for the logs ? Or any other way to change log format ?
self-answered
in the config file, you can config two format for message error like in this example :
[log]
log_writers[] = errorlog
string_message_format_trace = '{"source": "matomo", "level": "%level%", "tag": "%tag%", "time": "%datetime%", "message": "%message%", "trace": "%trace%"}'
string_message_format = '{"source": "matomo", "level": "%level%", "tag": "%tag%", "time": "%datetime%", "message": "%message%"}'
I don’t know if it’s documented anywhere, but it’s absent from the global.ini.php file I had in my version (4.10.1). I dug into Monolog plugin code to find it.
Still, I’m not sure about the added log_writers in my example. The errorlog generated is not formatted but it does format it somewhere else (found the message correctly formatted in my nginx error log). Maybe it’s still a prototype feature ?