Trouble with Logback / JUL configuration

Hallo everyone Im having some trouble with JUL logging and was wondering if somebody has had the same issue or else a good solution. My problem is that logback settings seem to be ignored by JUL. So if I have the following example: <logger name="test"><level value="debug"/></logger> java.util.logging.Logger logger = java.util.logging.Logger.getLogger(test); logger.log(Level.FINEST, finest); logger.log(Level.FINER, finer); logger.log(Level.FINE, fine); logger.log(Level.INFO, info); Only the info will be logged. I found the following JavaDoc which is the root of the problem: <http://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html#install%2 8%29> http://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html#install() This handler will redirect jul logging to SLF4J. However, only logs enabled in j.u.l. will be redirected. For example, if a log statement invoking a j.u.l. logger disabled that statement, by definition, will not reach any SLF4JBridgeHandler instance and cannot be redirected Is there a solution or a workaround for this problem? Like a logging.properties which enables everything on trace level? Greets and thanks flavio ----- Flavio Donzé Software Engineer My Blog: http://swissdev.blogspot.com/

Flavio Donzé wrote:
“This handler will redirect jul logging to SLF4J. However, only logs enabled in j.u.l. will be redirected. For example, if a log statement invoking a j.u.l. logger disabled that statement, by definition, will not reach any SLF4JBridgeHandler instance and cannot be redirected”
Hello Flavio, When you log using a jul logger, the jul logger gets invoked, and if it is enabled for the level with which it was invoked, and if SLF4JBridgeHandler was installed, then logs would go to SLF4J. In your example, you are using the FINE, FINER and FINEST levels which are all disabled by default (in jul). You just need to enable them by modifying the logging.properties file in use by your JVM. See $JAVA_HOME/lib/logging.properties wherer $JAVA_HOME is the folder where you installed your JDK. HTH, -- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

Hi Ceki Thanks for your reply, here how I solved it: URL logging = context.getBundle().getResource("logging.properties"); if (logging == null) { throw new IOException("logging.properties not found in com.softmodeler.osgi.over.slf4j"); } InputStream inputStream = logging.openStream(); LogManager.getLogManager().readConfiguration(inputStream); SLF4JBridgeHandler.install(); The loaded logging.properties contains only one line: .level= FINEST Now I get all the messages over logback, JUL does not print anything. Cheers flavio ----- Flavio Donzé Software Engineer My Blog: http://swissdev.blogspot.com/ -----Ursprüngliche Nachricht----- Von: logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] Im Auftrag von Ceki Gulcu Gesendet: Mittwoch, 17. Juni 2009 13:35 An: logback users list Betreff: Re: [logback-user] Trouble with Logback / JUL configuration Flavio Donzé wrote:
This handler will redirect jul logging to SLF4J. However, only logs enabled in j.u.l. will be redirected. For example, if a log statement invoking a j.u.l. logger disabled that statement, by definition, will not reach any SLF4JBridgeHandler instance and cannot be redirected
Hello Flavio, When you log using a jul logger, the jul logger gets invoked, and if it is enabled for the level with which it was invoked, and if SLF4JBridgeHandler was installed, then logs would go to SLF4J. In your example, you are using the FINE, FINER and FINEST levels which are all disabled by default (in jul). You just need to enable them by modifying the logging.properties file in use by your JVM. See $JAVA_HOME/lib/logging.properties wherer $JAVA_HOME is the folder where you installed your JDK. HTH, -- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user

Thanks for the feedback and sharing your code. You can accomplish the same with less: java.util.logging.Logger logger = java.util.logging.Logger.getLogger(""); logger.setLevel(java.util.logging.Level.FINEST); HTH, Flavio Donzé wrote:
Hi Ceki
Thanks for your reply, here how I solved it:
URL logging = context.getBundle().getResource("logging.properties"); if (logging == null) { throw new IOException("logging.properties not found in com.softmodeler.osgi.over.slf4j"); } InputStream inputStream = logging.openStream(); LogManager.getLogManager().readConfiguration(inputStream);
SLF4JBridgeHandler.install();
The loaded logging.properties contains only one line: .level= FINEST Now I get all the messages over logback, JUL does not print anything.
Cheers flavio
----- Flavio Donzé Software Engineer My Blog: http://swissdev.blogspot.com/
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

But then JUL would still print it's output to the default handler wouldn't it? handlers= java.util.logging.ConsoleHandler java.util.logging.ConsoleHandler.level = INFO java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter So I would have double log prints? cheers ----- Flavio Donzé Software Engineer My Blog: http://swissdev.blogspot.com/ -----Ursprüngliche Nachricht----- Von: logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] Im Auftrag von Ceki Gulcu Gesendet: Mittwoch, 17. Juni 2009 15:22 An: logback users list Betreff: Re: [logback-user] Trouble with Logback / JUL configuration Thanks for the feedback and sharing your code. You can accomplish the same with less: java.util.logging.Logger logger = java.util.logging.Logger.getLogger(""); logger.setLevel(java.util.logging.Level.FINEST); HTH, Flavio Donzé wrote:
Hi Ceki
Thanks for your reply, here how I solved it:
URL logging = context.getBundle().getResource("logging.properties"); if (logging == null) { throw new IOException("logging.properties not found in com.softmodeler.osgi.over.slf4j"); } InputStream inputStream = logging.openStream(); LogManager.getLogManager().readConfiguration(inputStream);
SLF4JBridgeHandler.install();
The loaded logging.properties contains only one line: .level= FINEST Now I get all the messages over logback, JUL does not print anything.
Cheers flavio
----- Flavio Donzé Software Engineer My Blog: http://swissdev.blogspot.com/
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://qos.ch/mailman/listinfo/logback-user
participants (2)
-
Ceki Gulcu
-
Flavio Donzé