Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 4 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 8 times, most recently from 3b5f5ba to 96357ee Compare July 19, 2023 12:37
@tvdijen tvdijen force-pushed the master branch 5 times, most recently from 7587851 to d523b31 Compare August 2, 2023 11:58
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from 8c90121 to d534e3b Compare September 5, 2023 08:09
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from bc1c5c8 to d0a5974 Compare October 17, 2023 21:17
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from ccb9b02 to 120a100 Compare December 1, 2023 14:34
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 6004a77 to 58bf8db Compare May 4, 2024 23:45
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.

None yet

2 participants