Better handling of multi-line logs (e.g., with backtrace)#311
Better handling of multi-line logs (e.g., with backtrace)#311bradjones1 wants to merge 1 commit intosimplesamlphp:masterfrom
Conversation
…ing code. Introduces option for 'json' log format, in which case syslog will json_encode() the log contents. Also demotes the message logging the error ID to a notice.
eaef53a to
4bd3fa1
Compare
|
Thanks for the PR @bradjones1! Could you provide some example outputs for both the default, backwards-compatible logging, and the new format with JSON? |
|
Hi again @bradjones1! I've recently enhanced a bit the handling of logs, including those with backtraces. Backtraces are now logged as debug, so they can be ignored easily if you want. Regarding the formatting in JSON, wouldn't that be possible if you provide a JSON-encoded string in the |
1c686ab to
eb20457
Compare
08ebb9c to
64fca25
Compare
7a53fc8 to
d73ae47
Compare
e5c0e21 to
d5616df
Compare
2e6ab04 to
32f9acc
Compare
7e3ea19 to
2523634
Compare
7b173cf to
3326beb
Compare
8ac729b to
a16cf6e
Compare
fc454de to
7ac76ae
Compare
29f7b69 to
1a911ce
Compare
c7c8357 to
fdbe001
Compare
a6df6e9 to
3b5f5ba
Compare
Hopefully this PR isn't too broad, but I've attempted to clean up some of the logging logic particularly when it comes to handling multi-line messages. Reading through the existing code, most messages destined for the log appear as $string, and a string is assumed, though the Logger's log() function includes an implode() if it's indeed passed an array.
I ship my logs off to an offsite log aggregation service, using rsyslog as an intermediary. Furthermore I like to package log messages as JSON, either in the application or with an rsyslog template. This PR is backwards-compatible with existing configurations but will result in only one "main" error message being logged, as opposed to the foreach() that was running which resulted in one log message per line. That can become a bit unwieldy with the backtrace.
If the logging service is syslog and the format is set to "json," the message is maintained as an array and is then JSON-encoded.
Also this downgrades the "Error report generated" message to a notice, since it is not itself the error, but simply a note about the logged error.
Includes some abstraction in Exception.php as the result of the removal of those foreach() loops.