In plain Java SE 6 environment:
Logger l = Logger.getLogger("nameless");
l.setLevel(Level.ALL);
l.fine("somemessage");
Nothing shows up in Eclipse console. l.info("") and above works just fine, but anything below fine just doesn't seem to work. What's could be wrong? TIA.
Even though the Logger level is set to ALL, the ConsoleHandler (the default Handler on the logger) still has a default level of INFO. This comes from the default logging.properties in JAVA_HOME/jre/lib
Other users have already given good answer why it happened (ConsoleHandler has a separate level variable). I reuse my application logger's level and copy it up to the parent hiearchy. Also provides easy way to refresh levels at runtime anytime I want.
Instead of looping through all handlers and set the logging level, I prefer to set only the level of the console handler:
An indivual at my workplace found the following to work:
If you just set the root or the handler to finest (exclusively) then it didn't work. When I set both to
FINEST
then it works. His explanation was:He further explained it using the following examples:
Logger myLogger
has a level ofFINEST
and a singleConsoleHandler myHandler
which has a level ofINFO
myLogger.fine("foo")
à message makes it past the logger’s filter, but gets stopper by the handler’s filter… Nothing output.myLogger.info("foo")
à passes both filters andfoo
is output.Now…
Logger myLogger
has a level ofINFO
and a singleConsoleHandler myHandler
which has a level ofFINEST
myLogger.fine("foo")
à message gets stopped by the logger’s filter and never makes it to the handler... Nothing output.myLogger.info("foo")
à passes both filters andfoo
is output.Now…
Logger myLogger
has a level ofFINEST
and a singleConsoleHandler myHandler
which has a level ofFINEST
myLogger.fine("foo")
à passes both filters and "foo
" is output.myLogger.info("foo")
à passes both filters andfoo
is output.You need to set the log level on both the handlers in the logger, and the logger itself. Logging is only performed at the "coarsest" of the two levels. Here is a logging class that does the job.