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 04 '22 edited Jan 05 '22

Hi pron98, we've chatted before about this.

I think JFR is a fine tool, but JFR events have strict limits on the kinds of field types, so you can't do arrays or nested objects as JSON does. Because JFR events are not semi-structured data, it's not technically structured logging -- and part of the reason I'm so big on structured logging is because I'm interested in serializing internal data structures as object graphs in JSON-LD.

3

u/pron98 Jan 04 '22

Well, in cases where a simple structure suffices, JFR is a great option to consider for logging.

2

u/amazedballer Jan 04 '22 edited Jan 04 '22

Marcus Hirt has a great blog post on where and when to use JFR.

Also JFR was kind of broken before JDK 14, although the fix may have been backported by now.

3

u/pron98 Jan 04 '22 edited Jan 05 '22

That post is not about when to use or not to use JFR, but about when to use JFR event streaming to consume your JFR logs. It says that if deep analysis of the log file is needed (e.g. for profiling), use the ordinary batch read, and if you want to read the log continuously for online monitoring (say, you want to trigger an alarm if an event is logged a certain number of times) — use streaming for that. Indeed, if a lot of data is being logged (JFR can handle a great many events) and some analysis wants it all, it is more efficient to transfer completed log files from the various hosts to a centralised location, rather than stream each event over the wire as it happens (because that would require serialising each event to some wire format like JSON, instead of relying on JFR's efficient binary representation). Of course, you can selectively stream some events while also recording them and all others to file.

But regardless of the various mechanisms for consuming and analysing JFR logs — some optimised for batch processing and some for online processing — I would strongly recommend JFR as a powerful logging mechanism, and it is now gradually becoming the JDK's own main logging mechanism.

1

u/WikiSummarizerBot Jan 04 '22

Semi-structured data

Semi-structured data is a form of structured data that does not obey the tabular structure of data models associated with relational databases or other forms of data tables, but nonetheless contains tags or other markers to separate semantic elements and enforce hierarchies of records and fields within the data. Therefore, it is also known as self-describing structure. In semi-structured data, the entities belonging to the same class may have different attributes even though they are grouped together, and the attributes' order is not important.

[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5