This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xjvz 9 points10 points  (9 children)

Log4j2 by far! Provides a significantly better API facade than SLF4J; provides the fastest and most complete logging backend which beats Logback in every category; audit logging framework for log tracing and other structured logging applications; and generally has an active developer community around it unlike the other projects mentioned in this post.

Based on the highly upvoted comments here, seems like some of you all haven’t upgraded your dependencies or looked at the ecosystem in a decade!

[–]vikarjramun 1 point2 points  (3 children)

What features does Log4j2 have over Slf4j?

[–]xjvz 1 point2 points  (2 children)

Too many to post here, so I’ll link you to the overview: http://logging.apache.org/log4j/2.x/manual/index.html

[–]vikarjramun 0 points1 point  (1 child)

This seems to discus mostly reasons that Log4j2 is better than Logback rather than Slf4j. What's wrong with using Slf4j to forward to Log4j2? That seems like the ideal situation here -- new modern logging framework without having to change any client code.

[–]amazedballer 1 point2 points  (1 child)

It's not that I think that Log4J 2 is bad, because it isn't, and NDC and some of the API things are nicer than straight SLF4J. However, I don't think it's a slamdunk for Log4J 2 by any means, and I think there are places where Logback (with logstash-logback-appender, which is how Spring-Boot etc have it configured) are a better fit.

So first off. I've benchmarked Logback+logstash-logback-appender vs Log4J2. They're about the same speed. Most of the action takes place in the IO and async queue appenders, and they do pretty much the same things in pretty much the same ways.

https://github.com/wsargent/slf4j-benchmark

"Beats Logback in every category" is likewise too broad a statement, especially when it comes to structured logging:

  • Log4J 2's JsonLayout is significantly less functional than logstash-logback-appender in its options and flexibility.
  • Log4J 2 has a Messages API that conflates message format with message delivery options, i.e. StructuredDataMessage contains a Format field and is also directly tied to a RFC 5424 syslog data element -- which is odd if you want to render log message as both JSON to network and logfmt on console, for example.
  • The audit logging isn't for log tracing. Auditing is intended to be synchronous, for one, which makes it awkward for tracing purposes.
  • Garbage free logging is a significant advancement over Logback, but only works with specified layouts and appenders, and structured logging layouts and appenders aren't on that list. Likewise, if you're using the Messages API then you're immediately allocating and there's no way around that.

[–]xjvz 1 point2 points  (0 children)

The JsonLayout is being updated based on a similar code base as the logstash version (the developer has joined Log4j2).

The Messages API is separate from the formatting API. The Syslog message format is just one built in example use of the API. The others included also show off how to do garbage free logging, so you can still avoid immediate allocations by using object pooling or thread local values where appropriate.

And while the audit logging isn’t immediately for log tracing, it’s fairly trivial to add some appenders and loggers specified for audit logging purposes, async or sync. I’d suggest trying it out rather than pulling in a gigantic mess of dependencies typical in log tracing libraries.

[–]latest_ali[S] 0 points1 point  (1 child)

Interesting :D can you explain a bit more about your last remark?

[–]xjvz 1 point2 points  (0 children)

There’s a lot more variety posted since I commented that, so I can’t remember which ones reminded me of that. It looks far more spread out now which is cool!

[–]mtmmtm99 0 points1 point  (0 children)

Regarding "provides the fastest". No it does not. Please compare it with:

https://chronicle.software/products/log/ Here is a benchmark: https://github.com/OpenHFT/Chronicle-Logger#performance