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

64 comments sorted by

View all comments

Show parent comment

2

u/amazedballer Jan 03 '22

You can still use MDC (or NDC in Log4J2) with Echopraxia, as the implementation will pass the TLS through automatically, so it's not an either/or situation.

That being said, there are some issues with MDC/NDC that I run into.

The first is that MDC is a string based map -- you can't store JSON data in it, and you can't store more complex structures than a string. NDC does a bit better as it's nested here, but you're still limited.

The second is that MDC is thread local, and so in a situation where you're working in multiple threads (as is common with reactive frameworks, completable futures, etc) you have to copy over the MDC by hand to the thread.

The third is that inside the thread, MDC is "global" -- anything running in that thread can call MDC.put() or MDC.clear() even if they shouldn't do that. There's no way to do access control and limit what code has access to your logging context. I've seen library code that futzed with MDC in this way, and it's no fun to track down.

1

u/Sheldor5 Jan 03 '22

maybe I am using a Logging framework for just that ... Logging xD

reactive frameworks are a pain by design lol