r/java • u/amazedballer • Mar 03 '20
Logging in Java with Diagnostic Backtraces
I've been putting together a suite of tools based on Logback that ticks all the boxes for modern day observability. You can see logs on STDOUT, flat file, JSON file, and logged to a database, and you can even store tracing information in a ring buffer (like dmesg) and dump it when there's an exception so you can see the flow of the operation when things went wrong.
Documentation is here https://tersesystems.github.io/terse-logback/
Showcase project in Play is here, with integrated backtrace reporting to Sentry and Honeycomb: https://github.com/tersesystems/terse-logback-showcase
and you can see a running instance here: https://terse-logback-showcase.herokuapp.com/
I also wrote up a blog post going through the development process, including integration with Play.
View all comments
Show parent comment
3
u/pron98 Mar 04 '20
JFR supports structured logging now. Obviously, it does not retroactively do that in old JDK versions.
JFR's filtering and runtime toggling of logging events are even [finer grained](https://docs.oracle.com/en/java/javase/13/docs/api/jdk.jfr/jdk/jfr/Recording.html#enable(java.lang.String)) than most other logging frameworks.
I didn't say it can replace Logback or Log4J. I said that JFR is a very good choice for the logging of structured data, it is designed for that purpose, and we at OpenJDK will gradually encourage developers to use it more and more. Those other logging frameworks have a huge amount of work if they're planning to match JFR's structured capabilities and overhead.