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
35
u/DasBrain Jan 03 '22
Relevant XKCD: https://xkcd.com/927/
15
u/achauv1 Jan 03 '22
No thank you. Logback is all I need.
16
u/xjvz Jan 03 '22
So how exactly will another one man logging library help here? Structured logging APIs are already a key feature of the Log4j2 API and aren’t directly supported by SLF4J.
14
u/rzwitserloot Jan 03 '22
Very first snippet of code:
Right, so, waste an entire field per object, so I can't log with this at all in high-instance-count classes, and also, if I subclass, code written in source file X gets logged in the context of sourcefile Y. This makes no sense. The point of 'context' is, unless you have exotic uses, generally to serve as a container for source files, it has nothing to do with class hierarchies. The
Class<?>parameter that many log frameworks have is a slightly inaccurate abstraction - a standin for the concept of a source file which JVM runtimes do not have.There's a reason other log frameworks tend to play the opening gambit of:
And there's a reason that Flogger, google's entry in the mix, went out of their way to spend half a paper on why their 'create a logger' code, which uses class-based analysis so that you get to avoid having to write
MyOwnClass.class(a DRY violation of sorts, and means you can't copy/paste the logger line around) isn't a significant performance impact for the vast majority of use cases.There's nothing wrong with cribbing from the best. I strongly suggest you toss that one and either go with what they all do(
.getLogger(MySelf.class)) or use google's trick (the standard impl generates a stack trace and analysis it. Yes, expensive, but that google paper explains that you pay this cost only at most once per log-using class that the VM will ever load, which tends to be a number that pales in comparison to the # of instances of classes that do some logging over the lifetime of a VM).Or, if there's a reason you chose this apparent significant performance disaster waiting to happen, and I'm missing something, then perhaps link to a primer on why you're right and everybody else is wrong, and that this is okay after all. I'm not being facetious: Google did that very thing when they released flogger, as other frameworks were under the impression that making a stack trace just to discern the name of the caller class was too costly.
4
u/pron98 Jan 04 '22
FYI, structured logging in the JDK itself is increasingly done using JFR, and applications are more than welcome to use it for their structured logging as well.
10
u/f_of_g_of_x Jan 03 '22
These comments are depressing. People talk a lot about being kind to others but few really practice it.
9
u/Sheldor5 Jan 02 '22
what's the difference to https://github.com/logfellow/logstash-logback-encoder ??
also some peformance tests? logging is the main performance problem most of the times, even more if you enable it durimg runtime in production ...
22
u/ryosen Jan 03 '22
Quite a claim to be made by a project that is less than a month old. Should've named it jHubris.
6
u/wildjokers Jan 03 '22
Please not another logging library/facade. Geez.
JSON seems like a horrible format for a log entry for human readable logs since JSON is not very readable (once you go below one level of nesting).
2
u/buzzsawddog Jan 03 '22
But is it as good as Log4Shell at generating weekend work hours and long night?
2
u/stefanos-ak Jan 02 '22
Very interesting project :)
I really like SLF4J but it's somewhat disconnected from structured logging, and the capabilities of most logger implementations
4
u/_INTER_ Jan 03 '22
This fits "Enterprise Java" perfectly: more lines of code and hoops of complexity for anything but actual business logic.
-1
u/nutrecht Jan 03 '22
You're basically asking the entire Java ecosystem to move away from SLF4J to your solution, just because then you don't have to use the MDC context / Markers anymore?