Different logging level between SFL4J and JDK logging
Asked Answered
B

2

15

I am using JDK logging as a logging framework and SLF4J as simple facade. I have some queries when I log different level logs.

SLF4J has following log levels

trace (the least serious)<br>
debug<br>
info<br>
warn<br>
error<br>
fatal (the most serious)<br>

JDK logging has following log levels

SEVERE (highest value)<br>
WARNING<br>
INFO<br>
CONFIG<br>
FINE<br>
FINER<br>
FINEST (lowest value)<br>

If I want to set the log level to DEBUG then that level is not available in JDK logging. Can anybody please explain how can we get the DEBUG level logging in this situation. Do we need to do any additional configuration for this situation?

Updated

this is my property file configuration

handlers = com.amc.logging.handlers.DebugLogHandler

com.amc.logging.handlers.DebugLogHandler.pattern=c:/logs/debug_log.log
com.amc.logging.handlers.DebugLogHandler.level=FINE
com.amc.logging.handlers.DebugLogHandler.formatter=java.util.logging.SimpleFormatter
com.amc.logging.handlers.DebugLogHandler.append=true

Please let me know where I went wrong.

Bernadette answered 4/4, 2013 at 10:8 Comment(4)
Duplicate? #4278938Interlude
I have changed the log level to FINE which mentiooned in the above link but still I am not getting the DEBUG level logging.Bernadette
The solution which you gave didnt help me to resolve my issue. I have updated my post with the my property file configuration.Bernadette
My solution to any JDK logging problem is to use log4j.Interlude
B
8

I have solved this issue with the help of bellow post.

slf4j logging with jdk – how to enable debug?

For DEBUG level logging in SLF4J we have to map FINE level in java.util.logging.

And we have to set the default logging level as FINE or lower level of FINE. This can be achieved by putting the bellow line in logging configuration file.

.level= FINE

Bernadette answered 4/4, 2013 at 12:54 Comment(0)
L
0

One further problem you have is that although you've defined a handler, you haven't assigned it to any loggers.

To assign it to the root logger, use

.handlers=com.amc.logging.handlers.DebugLogHandler

To assign it to a logger in your application, define the logger

com.company.application.package.level=FINE

And assign your handler to it: com.company.application.package.handlers=com.amc.logging.handlers.DebugLogHandler

Also, is com.amc.logging.handlers.DebugLogHandler a class that you defined yourself? Is it in your classpath? Because otherwise I don't think java.util.logging (JUL) will recognize it.

Try one of the handlers that comes with JUL:

handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler

And configure them with the level, log location and format that you want.

Here's an example logging.properties file: https://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_java.util.logging_(default)

It uses handlers from apache's juli implementation, but just substitute with classes from JUL: https://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html

Lotty answered 7/6, 2015 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.