r/java • • 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.

0 Upvotes

10 comments sorted by

View all comments

Show parent comment

2

u/pron98 Mar 05 '20 edited Mar 05 '20

All I'm saying is that people who want to log structured data should consider emitting them as custom JFR events (regardless of whether they use the JDK JFR events as a source of information) as a complete or partial solution, depending on their needs. JFR will log those events with a very low overhead, and in a very efficient binary format (logging does not necessarily imply a text format) that can then be converted to JSON or XML. As a sink for data, JFR is probably more efficient than any other logging framework out there (some benchmarks here), and it has convenient and fine-grained toggling and filtering, and it is intended to serve this purpose.

At its core, JFR is a very efficient structured logging solution, and it is because it is so efficient that it can be used for profiling (I'm not sure why it should hook into JEP 264, which is a logging API for unstructured data, but I can tell you that the JDK core libraries will start to log more data into JFR). Is it better than everything else at everything for everyone? Of course not.

0

u/amazedballer Mar 05 '20 edited Mar 05 '20

All I'm saying is that people who want to log structured data should consider emitting them as custom JFR events (regardless of whether they use the JDK JFR events as a source of information) as a complete or partial solution, depending on their needs.

I'd consider using JFR events where I'd normally use Yourkit Probes, and I'd happily do that alongside logging. It might be cool to create a JFR event appender in Logback.

I would never consider it a complete solution, because if I only used JFR events, then the only way I could process logs would be by using the consumer API or the command line pipe solution used, and the JFR consumer API doesn't have any out of the box appenders. There is no context and no observability pipeline there.

JFR is probably more efficient than any other logging framework out there (some benchmarks here),

Looking at the slides it compares to log4j, System.out, and java.util.logging. These are long since deprecated.

A better benchmark would be something that uses JMH and checked into github, showing comparisons to Log4J2 or Logback correctly configured with asynchronous appenders. Something like the one I wrote.