logging-log4j2
logging-log4j2 copied to clipboard
Modernize and split `log4j-jul`
The current log4j-jul artifact contains four different features:
- A custom
j.u.l.LogManagerimplementation. This implementation is actually rather generic and can be adapted to any kind of logging backend by implementing ano.a.l.l.j.AbstractLoggerAdapter. The defaultAbstractLoggerAdapterforwards all logging calls to the Log4j API. - An implementation of
o.a.l.l.j.AbstractLoggerAdaptercalledCoreLoggerAdapterthat forwards the JULLogger.setLeveland similar non-logging API method tolog4j-core. - A custom
j.u.l.Handlerimplementation calledLog4jBridgeHandlerthat forwardsLogRecords to Log4j API. This handler can be used if the user can not change the implementation ofj.u.l.LogManager. - Using the
Log4jBridgeHandleris very slow for log statements that are disabled in the Log4j API implementation, but not disabled in the default JULLogManagerimplementation. Thereforelog4j-juloffers a level propagator that modifies the level of JUL loggers, whenever the level of the corresponding Log4j Core loggers change. This feature of course depends onlog4j-core.
This PR:
- Removes
CoreLoggerAdapterand related classes. IMHO users should not usej.u.l.Loggerto modify the configuration of the logging backend. - Moves the level propagator to a new module
log4j-jul-propagator. Note that the level propagator idea comes from SLF4J/Logback wherejul-to-slf4jintroduces aLevelChangePropagatorinterface, but the implementation is in Logback. - Revamps the
o.a.l.l.j.LogManager:- It implements JUL methods that were introduced in Java 9.
- It improves the implementation of methods that accept a
sourceClassandsourceMethodparameters, by forwarding these parameters usingLogBuilder#withLocation(). - It fixes location detection, even if JUL
Filters are used.
The last part probably could be improved: I don't see why we should support j.u.l.Filters. We could drop the feature in 3.x.