How do I setup Java 9 so that System.Logger
instances write to log4j 2.10.0, instead of writing to JUL?
Log4j 2.19. 0 is the latest release of Log4j. As of Log4j 2.13. 0 Log4j 2 requires Java 8 or greater at runtime.
Navigate into the "META-INF" sub-directory and open the file "MANIFEST. MF" in a text editor. Find the line starting with "Implementation-Version", this is the Log4j version.
Starting with version 2.4, Log4j 2 provides an API for programmatic configuration The new ConfigurationBuilder API allows you to create Configurations in code by constructing component definitions without requiring you to know about the internals of actual configuration objects like Loggers and Appenders.
Log4j is a fast, reliable and flexible logging framework which is written in java. It is an open-source logging API for java. Simply the logging means some way to indicate the state of the system at runtime.
This is the paragraph you refer to:
This release contains the first support of Java 9 as well as bugfixes and minor enhancements. The Log4j API was modified to use
java.util.ServiceLoader
to locate Log4j implementations, although the former binding mechanism is still supported. The Log4j jar is now a multi-release jar to provide implementations of the Java 9 specific classes.
It doesn't mention System.LoggerFinder
and indeed a full-text search of the repo (of version 2.10) didn't turn up any mention of "LoggerFinder" and nothing promising for "java.lang.System". I'm hence sure that Log4J 2.10 does not yet integrate with JEP 264: Platform Logging API and Service.
What the release notes seem to refer to instead is that Log4J now uses the ServiceLoader
API when looking for implementations of its own API.
If you really need/want Log4J to log these messages, you can roll your own adapter as I did here for SLF4J. All you need are Log4J adapters for System.Logger
and System.LoggerFinder
(both straightforward to implement if you skimp on some of the details) and either a META-INF/services
file or a module declaration like the following:
module org.slf4j.platform {
// put the right module name here
requires log4j;
provides java.lang.System.LoggerFinder
// put the right class name here
with org.log4J.Log4JSystemLoggerFinder;
}
Launching your application with that artifact will then lead to Log4J getting platform log messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With