Hello, I just discovered and am currently trying out the Logger class (after deciding my homemade logger class wasn't quite cutting it anymore). But I seem to be having issues logger the FINE, FINER, and FINEST level log messages. Basically, everytime I attempt to log a message using the Logger.fine() Logger.finer(), and Logger.finest() messages, they don't reach the logger's Handlers. I've tried setting the log level to Level.FINEST and Level.ALL. But neither seem to work. I've also looked at Sun's implementation of the Logger.finest method, and there doesn't seem to be anything fancy there:
A Logger has a Level which determines which messages it will log. Any message with lower Level than the Logger is ignored - that's what's happening to you here. The Level can be set two ways (maybe more):
Use the Logger's setLevel() method, e.g. tstLggr.setLevel(Level.FINEST)
Edit the log configuration file, found in [JDK dir]/jre/lib/logging.properties, to either configure a named logger with a particular level, or set the global level for logging to the console to some other level.
See the APIs for Logger, LogManager, and Level for more details.
Thanks for your response and suggestion. But I believe I am setting the level properly. I have read the APIs but maybe I'm misunderstanding something... I am not actually using the LogManager because I not handling a number of Loggers. I am only testing out how its methods work. Anyhow, here is a revised example and its output demonstrating the setting of the Logger's log level:
You have to call setLevel on your handler. So should do the trick. From the StreamHandler javadoc : Configuration: By default each StreamHandler is initialized using the following LogManager configuration properties. If properties are not defined (or have invalid values) then the specified default values are used. java.util.logging.StreamHandler.level specifies the default level for the Handler (defaults to Level.INFO). [ April 14, 2003: Message edited by: Don Kiddick ]
I just thought I'd add something else I've discovered... It looks like when I add a FileHandler to the Logger, it prints the FINEST msg. Although the StreamHandler that prints to stdout still will not.
From the FilHandler javadoc : Configuration: By default each FileHandler is initialized using the following LogManager configuration properties. If properties are not defined (or have invalid values) then the specified default values are used. java.util.logging.FileHandler.level specifies the default level for the Handler (defaults to Level.ALL).