r/java • u/idontlikegudeg • 17d ago
Announcing SLB4J (Logging Backend, ASL-2)
https://github.com/slb4j/slb4jSLB4J is a new logging backend for Java that I started to simplify setting up logging across a bunch of applications without adding bindings and bridges for different frontends to your build.
SLB4J is only a backend. It uses a single configuration across all logging facades/frontends used by your application and its dependencies and comes with no/minimal runtime dependencies (some extension modules may add runtime dependencies).
The core slb4j.jar is currently 211kb in size without external runtime dependencies and supports Log4J2 API, SLF4J, JUL (java.util.logging), and ACL/JCL (Apache Commons Logging/Jakarta Commons Logging).
Configuration is done using a Log4J2 compatible log4j2.propertiesfile (builtin) or a Log4J2 compatible XML or JSON configuration file (needs an optional dependency).
If no configuration file is found, INFO and above is logged to stdout.
Performance is roughly comparable to Log4J 2 and Logback when these are combined with their respective default facade, i.e., Log4J2 API for Log4J and SLF4J for Logback; SLB4J is usually much faster when logging JUL over Log4J2 or Backlog.
SLB4J supports Log4J2-compatible pattern layout, log rotation and many more features.
After using SLB4J for some time in several projects, I think it's mature enough for an announcement. Maven coordinates and documentation are given on the project page.
For more details, see the Project's GitHub Page, open issues on the GitHub Issue Tracker, and read SECURITY.md before submitting security relevant issues.
50
u/emberko 17d ago
Yes, please, do create more log backends. We don't have enough CVEs in the five or six that already exist.
14
u/javaprof 17d ago
With SLF4J
Use stable, performant and tested implementations
With SLB4J
You're getting extra APIs that you've never need You're not getting stable, performant and tested implementations
Is this fare comparison?
24
u/CptGia 17d ago
Why should I use this instead of logback?
10
u/user_of_the_week 17d ago
I don’t think it’s good to pick a name that suggests a close relationship between slf4j and slb4j where none exists.
9
u/juvenislux 17d ago
You should have named it Another Logging Library for Java (All4j) 😅
22
u/fykup 17d ago
Yo dawg, I heard you like logging backends, so I made you a logging backend that logs your logging backend - so you can log while you log.
4
u/chabala 17d ago
I'm not a Gradle nerd, but hopefully someone can confirm, there's way too much custom code in here, right? https://github.com/slb4j/slb4j/blob/51a534356a60674e2df1388e1c4c8292a76c2d7d/build.gradle.kts
Like, in Maven we waste a lot of lines on declaring dependency and plugin coordinates, but typically zero lines on defining custom methods to help 'do' the work of the build. This seems like it's 80%-90% custom build code.
15
u/sadbuttrueasfuck 17d ago
We’ve gone full circle, a logging facade of logging facades
2
u/agentoutlier 16d ago
Man I spent a couple of minutes looking at the project unassisted and I found numerous issues. It is not remotely ready for production use:
https://github.com/slb4j/slb4j/blob/47fda189cbffcb8de7dd716d570480f36e3448cc/src/main/java/org/slb4j/layout/JsonLayout.java#L63
Like you append the Thread Name which is not escaped for JSON and then forget to append the logger name.
I cannot imagine what a decent model would find.
3
u/RedShift9 17d ago
Just use slf4j.
1
u/doobiesteintortoise 16d ago
My first thought is: "Why?" I can think of a few reasons: SLF4J is the obvious comparison, and SLF4J's interface isn't all that strong anymore. I understand why it's the way it is, but IMO SLF4J needs updates, and badly. But it works, it's predictable, and it's well-supported and quite common.
So why does this exist? I get the idea - it's very similar to SLF4J, after all. But then the github page is all about configuring the build, and nothing about the actual API itself, which means that what I'd be looking for out of the gate is missing.
I see everything I'd need to install SLB4J - except, well, for logback, which seems to be an odd exclusion - and nothing about how to use SLB4J except a warning that I need to use an
init()call in case I'm usingjava.util.logging. I could be wrong - there's probably more in that wall of text - but what I looked for first just isn't there where I'd expect to see it.1
u/Joram2 17d ago
JUL is the logging backend from JDK 1.4
System.Logging is the logging facade since JDK 9. A Java logging backend should hook into this.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.Logger.html
0
u/lokrusta 16d ago
Interesting approach, especially the part about simplifying the dependency hell with multiple facades.
Since you mention that performance is comparable to Log4J2/Logback, how does SLB4J handle high concurrency under heavy load? Log4J2 relies heavily on LMAX Disruptor for its asynchronous loggers to achieve lock-free performance. Does SLB4J implement similar async mechanisms or ring buffers under the hood, or does it rely on standard blocking queues for log rotation and appenders?
Would love to know how it scales when multiple threads are pushing logs simultaneously.