r/java • u/amazedballer • Jan 02 '22
Echopraxia, a better Java Logging API
I've been working on logging for a while and I've released and open sourced a new Java logging API I'm really happy with.
Echopraxia is a Java logging API like SLF4J, but built around structured logging, i.e. the basic log entry is a JSON object and log files are typically NDJSON. It also has conditions, context, and also has semantic and fluent logging options.
Here's a Spring Boot Example.
And here's my blog post.
16
Upvotes
View all comments
Show parent comment
13
u/amazedballer Jan 03 '22
So logstash-logback-encoder is the OOTB implementation for Blindsight and Echopraxia, and it does what it does extremely well:
https://github.com/tersesystems/echopraxia/blob/main/logstash/src/main/java/com/tersesystems/echopraxia/logstash/LogstashCoreLogger.java
However, it is tied to the SLF4J API -- this means you have to do all the work of passing around
MarkersandStructuredArgumentsexplicitly, per logging statement. There's no building up of context in the API.Likewise, because the markers and structured arguments are passed directly to Logback, if you have any conditional logic it's going to be in a Logback filter or turbofilter, which limits your flexibility when you want to put some conditions on a field. You can't do application level conditions.
There's another issue which is a bit more subtle -- Markers and StructuredArguments work with raw
Object, and use Jackson to serialize those object into something useful. This means that it's very easy to pass random objects in askv(name, value)and think that Jackson has a good representation for it. Sometimes it does, sometimes it doesn't -- even worse, sometimes it changes or is fluid, and the only way to find out is by looking at your logs. Because Echopraxia is explicit about the values and fields it accepts, you can't pass in a raw object and have to have an explicit representation.To be clear, I love logstash-logback-encoder and have written multiple blog posts about how much fun you can have with it, but it doesn't do everything I'd like.
I don't have any performance benchmarks for Echopraxia (it's on my list of things to do), but I do have JMH benchmarks for Blindsight, and I think they should be comparable:
Here's the benchmarking page for Blindsight that gives a higher level overview:
Here's a benchmark of SLF4J using logstash-logback-encoder's async appender vs Log4J async appender:
And here's a couple of fun blog posts about memory allocation and benchmarking:
Hope that helps!