'Java System Logger on WildFly
Since JDK 9 we have a new Java Logging API:
- https://docs.oracle.com/javase/9/docs/api/java/lang/System.Logger.html
- https://www.baeldung.com/java-9-logging-api
- https://blog.frankel.ch/system-logger/
It's more like a facade, without real logging implementation, but relying on existent logging framework.
We can use this API on Wildfly (with JDK 11), but it binds on JUL (Java Util Logging, default bind on JDK 11), giving log outputs levels from JUL as SEVERE or FINE instead of ERROR or INFO, respectively.
So, I would like to change this, making Java System Logger binds to JBoss Logging Framework (the default on Wildfly).
Following tutorials, I created a custom LoggerFinder
and a System.Logger
implementation that points to JBoss Logger.
Then I have tried to create a META-INF/services/java.lang.System$LoggerFinder
file pointing to my LoggerFinder implementation, as stated on 3rd link above, but with no luck. Tried to put this file on lib jar, app war, app ejb jar and app ear.
Resuming:
- Actual: System.Logger -> JUL
- Needed: System.Logger -> JBoss Logger
Update 1
I see that WF has a LogManager lib that should handle this (jboss-logmanager-1.1.18.Final.jar):
- https://github.com/jboss-logging/jboss-logmanager/blob/2.1.18.Final/src/main/java9/org/jboss/logmanager/JBossLoggerFinder.java
- https://github.com/jboss-logging/jboss-logmanager/blob/2.1.18.Final/src/main/resources/META-INF/services/java.lang.System%24LoggerFinder
But it appears that this LogManager is not loaded.
Update 2
Documentation on LoggerFinder says that:
A logger finder is a concrete implementation of this class that has a zero-argument constructor and implements the abstract methods defined by this class. The loggers returned from a logger finder are capable of routing log messages to the logging backend this provider supports. A given invocation of the Java Runtime maintains a single system-wide LoggerFinder instance that is loaded as follows:
- First it finds any custom LoggerFinder provider using the ServiceLoader facility with the system class loader.
So, I think that org.jboss.logmanager is not loaded on system class loader. How can I add org.jboss.logmanager to system class loader, and, it's safe to do this?
Update 3
So, I tried to follow some posts on Internet to enable org.jboss.logmanager, changing -Djboss.modules.system.pkgs
(I don't know what it does), adding -Djava.util.logging.manager
and adding -Xbootclasspath/a:...
. Tried multiple combinations of those startup parameters, but it always failed with error or not changing log level names. JBoss LogManager is a multi release jar, so maybe there is something related to it.
Then I build my own custom LoggerFinder implementation, much the same like JBoss LogManager, and tested it in Eclipse with success. In Eclipse I added my jar into classpath user entries of the WF run configuration (don't know what this reflects on WF startup). Now I need to know how to add this jar to WF system class path, I have tried -Xbootclasspath/a:...
parameter, but this works partially, my LoggerFinder is loaded, but log messages do not hit log handlers (messages are lost).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|