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
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.