klogging / klogging

Kotlin logging library with structured logging and coroutines support
https://klogging.io
Apache License 2.0
174 stars 19 forks source link

Order of log events #278

Open realdadfish opened 1 month ago

realdadfish commented 1 month ago

So, the default configuration of klogging says that log levels higher than WARNINGs are logged immediately, whereas logging of INFO levels and below happens asynchronously. This will lead to the problem (obviously) that the log order cannot be guaranteed anymore, especially if the log output is directly processed log message after log message and not "cached, sorted and dumped" at some later time.

I'm not exactly sure how this can be handled properly by a custom EventSender, maybe through some kind of "flushing" signal?

realdadfish commented 1 month ago

Also, on a related note, is there a way to synchronize / join on the pending / running coroutines? E.g. by remembering the started Job instances from launches and join on them? This is just a minor thing to stabilize my tests :)

mjstrasser commented 1 month ago

You can configure all logging to be direct by setting minDirectLogLevel. See Direct logging for details. It is not available on a per-logger or per-sink basis.

You can’t join a running coroutine from outside, as far as I know.

realdadfish commented 1 month ago

The prospect of having zero overhead logging is something I don't want to loose however. What if every log action is executed async and you provide a method to join on the last launched job(s) which one would have to call as last method in an UncaughtExceptionHandler or just before System.exit()?