3 ms·
> Then apache decides to put new people on log4j, do a backward incompatible v2 design that nevertheless is worse than slf4j. Why? Because the original Log4j a
by layer8 4y ago
> Then apache decides to put new people on log4j, do a backward incompatible v2 design that nevertheless is worse than slf4j. Why?
Because the original Log4j author wanted to do his own thing for a Log4j successor (slf4j/logback), and the Apache Log4j maintainers also had ideas about a next-gen framework and wanted to do that.
That’s Open Source, everyone can do their own thing if they like, and some things will get adopted more than others. Log4j2 got the most adoption because they had the Log4j “brand” and the Apache backing and more company-backed(?) maintainers.
I don’t consider java.util.logging to be braindead. It can in principle be used as a logging facade like slf4j, but not too many do that, and Log4j 1 had come first and kept that momentum.
The real mistake was for Java to not have a standard logging API earlier. (It took six years after Java 1.0.)
- YetAnotherNick 4y agoHearing logging library and next-gen framework in the same sentence would never not make me laugh.
- twic 4y agoI use java.util.logging in a few apps, to cut down on dependencies, and i consider it to be fairly braindead. The fundamentals are okay, to the extent that they are copies of log4j, but there are a bunch of little things that just aren't done right, like: - logging methods taking arrays rather than varargs (this would be a trivial change!) - there being no way to create a SimpleFormatter with a custom format in code other than setting a system property before creating it - there being no Logger:getLogger override which takes a class, only strings At some point, i am going to write a little facade which wraps jul and fixes the papercuts, which feels like a very silly thing to be doing!
- layer8 4y agoThose are cosmetic issues, in my book. The basic architecture is sound. In any serious application you will want to have a central logging wrapper anyway (I always use one), which automatically takes care of the varargs issue. The implementation of SimpleFormatter is 30 lines that you can easily copy and adjust as needed, including with your own custom format. Regarding logger names, I always define an explicit set of logger names for the application, because that makes the logger names independent from implementation-detail subpackages, and any operations-side log filtering based on logger names will remains stable, regardless of how you refactor your implementation into Java packages. Basically, I see the logger names as part of the external interface of the application, and therefore I want to have them decoupled from the internal package structure, so that mere refactorings don't break that interface. You can still easily find all program locations that log to a specific logger, for example by Find Usages on the respective static Logger constant.
- EdwardDiego 4y ago- the console appender writes to stderr.
- hyperman1 4y agojava.util.logging was braindead because it wanted to know the class and method doing the logging. If not provided, it threw and catched an exception and filtered the stack trace to detect its own caller. Throwing an exception was a very slow operation. I see they did some optimizations to do this work lazily if needed. But when log4j 1 was on its peak, that wasn't done, and using the built in logger was slow enough to have measurable impact . See https://github.com/openjdk/jdk/blob/6765f902505fbdd02f25b599f942437cd805cad1/src/java.logging/share/classes/java/util/logging/LogRecord.java https://github.com/openjdk/jdk/blob/6765f902505fbdd02f25b599... at the bottom.