I'm using the Java Logger for the first time and noticed it is possible to set the logging level either through handler.setLevel(...)
or through logger.setLevel(...)
. I can't seem to find a difference though. Is there a difference? And if there is, what is the recommended way to do it?
views:
54answers:
1
+1
A:
The logger is associated with a specific class. However, you can have multiple handlers that are associated with that logger. If you set 'the' handler level instead of the logger level you just need to make sure you are setting the correct handler. Unless you are using multiple handlers and need a fine level of granularity in your logging, it would be best if you just adjusted the logger level and left the handlers alone.
Check out this article. It gives a good description of how the handlers and loggers work together.
amischiefr
2009-12-02 14:26:02
Thanks a lot, that's indeed a thorough explanation you linked there. Better than the ones I found. I didn't even think about using multiple handlers with different levels. That makes a lot of sense indeed. In fact I just implemented this so the console only shows warnings while the loggile logs info too. Also, to add to your reply, a good reason I now discovered to not set the level at the handler is that the default handlers would still catch info+.
janb
2009-12-02 14:45:01