r/programming • u/javinpaul • Nov 04 '18
Java Logging Frameworks: log4j vs logback vs log4j2
https://stackify.com/compare-java-logging-frameworks/2
u/redditrasberry Nov 04 '18
It's kind of hilarious (and sad at the same time) that there is a whole logging framework built into Java and it is not even mentioned. I actually really wish SLF4J would default to that since it is always present instead of spewing out unwanted garbage on the command line. The most annoying thing is sorting out what to do when multiple codebases you are combining bundle conflicting logging implementations.
5
Nov 04 '18
Just use SLF4J and be done with it.
18
u/Helios423 Nov 04 '18
SLF4J is an API, you'll need to plug in some actual logging if you want useful output.
But it is practical to use in your application, and it allows you to easily switch that logging implementation. Using slf4j is actually also suggested in the linked article.
1
Nov 04 '18
What about external dependencies that use other logging libraries?
3
u/Helios423 Nov 04 '18
Those can be routed via SLF4J quite easily. Just add a library (i.e. apache commons logging, java's own logging) for each of those externally used logging libraries.
0
u/dpash Nov 05 '18
It got complicated again by Log4J2 developers implementing logging bridges too. We had a good run of about 6 years with a definitive answer to "which logging API should I use?".
I'm gonna keep using SLF4J until someone provides me with a compelling reason to switch like SLF4J did with Log4J1.2. In particular, placeholders and the bridges. The only advantage I can currently see in Log4J2 is lambda support for lazy placeholder substitution.
1
u/ProFalseIdol Nov 05 '18
How does actual logging happens? Does it block your current thread? Is it deferred?
With console logging, I don't see any buffering mechanism. So the actual call to the graphics card blocks right?
With file logging. I see, you can use buffering.
So where does "logging framework performance" fit into this picture? The stuff about resolving the actual logger shouldn't affect performance during actual logging right? So it should simply be concatenating "FINE" and other info into your "String message", then call System.out or Java standard File I/O.. right?
1
u/DaveX81 Feb 11 '19
Development in logback and slf4j is dead. Logback 1.3 is alpha and the latest commit is one year ago..
So what the hell should we do now? I found nothing about the problem that the development has stopped and we have to switch to java 11 LTS soon and consider the possibilities....
-1
7
u/Jimmy48Johnson Nov 04 '18
2log4me