X Tutup
Skip to content

Better handling of multi-line logs (e.g., with backtrace)#311

Open
bradjones1 wants to merge 1 commit intosimplesamlphp:masterfrom
bradjones1:logging-flexibility
Open

Better handling of multi-line logs (e.g., with backtrace)#311
bradjones1 wants to merge 1 commit intosimplesamlphp:masterfrom
bradjones1:logging-flexibility

Conversation

@bradjones1
Copy link
Contributor

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.

…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.
@jaimeperez
Copy link
Member

Thanks for the PR @bradjones1!

Could you provide some example outputs for both the default, backwards-compatible logging, and the new format with JSON?

@jaimeperez
Copy link
Member

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 logging.format configuration option? In case it's not possible, or you need something more elaborate, I think it might make sense to have a separate log handler for this. That's another improvement I introduced recently. Now it's possible to use custom log handlers just by implementing the interface \SimpleSAML\Logger\LoggingHandlerInterface, making the class available for the autoloader, and referencing it in the logging.handler configuration option.

@tvdijen tvdijen force-pushed the master branch 3 times, most recently from 1c686ab to eb20457 Compare August 17, 2020 20:43
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 08ebb9c to 64fca25 Compare July 2, 2021 14:12
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 7a53fc8 to d73ae47 Compare September 26, 2021 13:03
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from e5c0e21 to d5616df Compare January 9, 2022 11:00
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from 2e6ab04 to 32f9acc Compare November 23, 2022 18:24
@tvdijen tvdijen force-pushed the master branch 6 times, most recently from 7e3ea19 to 2523634 Compare January 5, 2023 16:31
@tvdijen tvdijen force-pushed the master branch 10 times, most recently from 7b173cf to 3326beb Compare March 20, 2023 22:59
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 8ac729b to a16cf6e Compare April 25, 2023 08:33
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from fc454de to 7ac76ae Compare May 3, 2023 08:31
@tvdijen tvdijen force-pushed the master branch 6 times, most recently from 29f7b69 to 1a911ce Compare May 12, 2023 16:07
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from c7c8357 to fdbe001 Compare June 12, 2023 14:28
@tvdijen tvdijen force-pushed the master branch 7 times, most recently from a6df6e9 to 3b5f5ba Compare July 19, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup