Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logging "FINEST" messages using java Logger

 
Spencer J Lee
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    Spencer J Lee
    Ranch Hand
    Posts: 30
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 580
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 30
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 580
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 30
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 18671
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry, Spencer - I should have looked at your code more closely. Good that others were paying more attention.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic