aspose file tools*
The moose likes Java in General and the fly likes Logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Logging "FINEST" messages using java Logger" Watch "Logging "FINEST" messages using java Logger" New topic
Author

Logging "FINEST" messages using java Logger

Spencer J Lee
Ranch Hand

Joined: Mar 19, 2003
Posts: 30
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:

My test class looks like the following:

I can't figure out what I'm missing. Thanks ahead of time for all your help.
Spencer
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


    "I'm not back." - Bill Harding, Twister
    Spencer J Lee
    Ranch Hand

    Joined: Mar 19, 2003
    Posts: 30
    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:

    And the output:

    Thanks,
    Spencer
    Don Kiddick
    Ranch Hand

    Joined: Dec 12, 2002
    Posts: 580
    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 ]
    Spencer J Lee
    Ranch Hand

    Joined: Mar 19, 2003
    Posts: 30
    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.
    Don Kiddick
    Ranch Hand

    Joined: Dec 12, 2002
    Posts: 580
    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).

    Read the javadoc !!
    Spencer J Lee
    Ranch Hand

    Joined: Mar 19, 2003
    Posts: 30
    Thanks Don. That explains everything. I'm in the middle of reading the docs right now. I guess I missed the documentation for the Handlers.
    Jim Yingst
    Wanderer
    Sheriff

    Joined: Jan 30, 2000
    Posts: 18671
    Sorry, Spencer - I should have looked at your code more closely. Good that others were paying more attention.
     
    wood burning stoves
     
    subject: Logging "FINEST" messages using java Logger