-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.util.logging (JUL) messages below INFO level are not recorded in Karaf logs #520
Comments
By default, I've created this BundleActivator: package grgr.test;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.StructuredDataMessage;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.LoggerFactory;
public class ActivatorLogging implements BundleActivator {
private static final Logger LOGGER = LogManager.getLogger(ActivatorLogging.class);
public static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ActivatorLogging.class);
@Override
public void start(BundleContext context) throws Exception {
StructuredDataMessage msg = new StructuredDataMessage("1", "message", "event");
msg.put("testKey", "testValue");
LOGGER.debug(msg);
LOG.debug("From SLF4J");
java.util.logging.Logger.getLogger(ActivatorLogging.class.getName()).fine("\"fine\" From java.util.logging");
java.util.logging.Logger.getLogger(ActivatorLogging.class.getName()).finer("\"finer\" From java.util.logging");
java.util.logging.Logger.getLogger(ActivatorLogging.class.getName()).finest("\"finest\" From java.util.logging");
}
@Override
public void stop(BundleContext context) throws Exception {
}
} And added this to Karaf's
(See - I have Log4j2 backend, so I need Log4j2 configuration). And I got this in the log file (
|
I did compile your example as-is. Here is the output in
So still not JUL output. Note 1: I'm using Eclipse Equinox as OSGi system bundle. I will retry with a very plain install "vanilla" fresh install, i.e. without Windows Service and without change the OSGi system bundle from Felix to Equinox to see if I've more chance PS. here is my MANIFEST.MF:
|
I just realized that I've changed in the Windows Service installation, the So in the fresh "vanilla" installation, Edit: after double checking I discovered that the bundle was not started, starting it, I get the same output:
Still no messages from java.util.logging |
Tested on Linux, still vanilla Karaf installation:
Still no messages from |
Please show me the changes you made to your original Karaf 4.4.3 installation (that you've chosen Equinox and what exactly did you add to If possible, please attach the bundle (source or jar). This simply must work ;) |
Some clarifications: For my project I made an "Windows Service" of the Karaf installation using Equinox as OSGi System bundle. But to test your example I downloaded the latest version, i.e. version 4.4.3, of Karaf OSGi Runtime and deployed it on both a Windows machine and a Linux machine, plain vanilla, i.e. no change for Equinox, still using Felix as it is configured by default! Deployed the zip (Windows), tar.gz (Linux) in both OSes in the current logged-in user's home directory, started it on both OSes from command line (i.e. no Windows Service, no Unix Daemon) with current logged-in user privileges (note the user hasn't the Windows Admin privilege, and on Linux it is not the root user and Karaf has not been started with sudo) The only thing I changed to fresh install is the
Then I deployed the bundle. Writting these lines, I just re-do all these steps on the Linux machine. Shell:
Karaf:
karaf.log
Edit: Karaf 4.4.3 instead of 4.4.2 (same outcome) |
Hereby your code compiled and exported as "Plug-in Development => Deployable plug-ins and fragments" (Eclipse Plugin == OSGi bundle) by Eclipse IDE for RCP and RAP Developers Note: I had to rename the extension from ".jar" to ".zip" in order to have Github accepting the file attachment. |
OK, I've checked your example (and removed After a quick debugging, I have another reason to NOT use JUL logging ;) The problem is that pax-logging-log4j2 (default backend used by Karaf 4.4) can alter levels of only existing JUL loggers. If you obtain a JUL logger after pax-logging-log4j2 was started/activated, you simply get a logger with default I'll think (but not this week) about some hacking into the JUL internals, so future loggers use some hand-crafted instances of For now, I recommend to switch to de-facto standard SLF4J ;) Yes - I treat it like this. I know that JavaEE advocates won't agree, but this is quite similar situation to Spring Framework being de-facto standard of Java Enterprise development. |
Also when I start this sample bundle, then restart |
Doing the same steps Karaf:
I confirm that I can see in
Thank you! Now I've a workaround! |
Still I would like to emphasis that going for Possibly I could pick a different logging library for the bundles that that I'm developing. That said to come back to the constraint aspect, I'm not the owner of the other bundles that are still using java.util.logging, e.g. SQLServer JDBC Driver, or any other JDBC Driver relying on java.sql.Driver.getParentLogger() I believe that my troubleshooting nightmare began with I mean if So would it be possible to ...
|
Thanks again for your analysis. Definitely there's a problem with JUL logger configured after the backend has been configured. However, because only you've found it, it may mean that JUL is not that popular ;) Some ancient (without Sure - Log4J has CVEs, but it also means it's used, analyzed and taken care of. To be honest I think JUL is quite limited (imagine multiple WARs configured in Tomcat, each trying to configure logging differently) and mostly usable with flat-classpath deployments... So I'll definitely have a look at proper configuration of JUL - in the scenario you've found when the logger is obtained after Log4J2 / Logback is configured. |
Tomcat has since a long time addressed this issue with JULI, cf. Logging in Tomcat To my point of view, java.util.logging (JUL), wherever we like it or not, should be considered as a first class citizen as it is the logger that comes along with the JDK. I appreciate that you envision to put in place another hack to cover this corner case, *) E.g. #519 provides a record of |
I found this bug today, when I'm trying to make CXF little bit more verbose. Workaround works, but I lost some time to found what is going on in pax-logging JUL support. Maybe we need an information about known bug in docs? |
As mentioned in ops4j/org.ops4j.pax.jms#65, documentation is a bit lacking in ops4j projects. These are community driven project with quite little interest these days (OSGi's golden age is long gone I guess...). (Un)fortunately, known bugs should be simply visible at this page ;) https://github.com/ops4j/org.ops4j.pax.logging/issues And I really know that this particular problem can be fixed - I just didn't have time to do it... |
I found this issue today when trying to enable low level logging for the MS SQL JDBC driver which (as mentioned above) uses JUL. @ffays suggestion of an option to not try and take over JUL and just let me write a logging.properties would work for me. |
Deploying Karaf 4.4.3 using Equinox OSGi System Bundle, log messages from java.util.logging.Logger below the INFO level (i.e. FINEST, FINER and FINE) are not recorded in karaf.log
The text was updated successfully, but these errors were encountered: