The java.util.logging.Level documentation does a good job of defining when to use a log level and the target audience of that log level.
Most of the confusion with java.util.logging
is in the tracing methods. It should be in the class level documentation but instead the Level.FINE
field provides a good overview:
FINE is a message level providing tracing information. All of FINE, FINER, and FINEST are intended for relatively detailed tracing. The exact meaning of the three levels will vary between subsystems, but in general, FINEST should be used for the most voluminous detailed output, FINER for somewhat less detailed output, and FINE for the lowest volume (and most important) messages. In general the FINE level should be used for information that will be broadly interesting to developers who do not have a specialized interest in the specific subsystem. FINE messages might include things like minor (recoverable) failures. Issues indicating potential performance problems are also worth logging as FINE.
One important thing to understand which is not mentioned in the level documentation is that call-site tracing information is logged at FINER
.
If you log a message as FINE
you will be able to configure logging system to see the log output with or without tracing log records surrounding the log message. So use FINE
only when tracing log records are not required as context to understand the log message.
FINER indicates a fairly detailed tracing message. By default logging calls for entering, returning, or throwing an exception are traced at this level.
In general, most use of FINER
should be left to call of entering, exiting, and throwing. That will for the most part reserve FINER
for call-site tracing when verbose logging is turned on.
When swallowing an expected exception it makes sense to use FINER
in some cases as the alternative to calling trace throwing
method since the exception is not actually thrown. This makes it look like a trace when it isn't a throw or an actual error that would be logged at a higher level.
FINEST indicates a highly detailed tracing message.
Use FINEST
when the tracing log message you are about to write requires context information about program control flow. You should also use FINEST for tracing messages that produce large amounts of output data.
CONFIG messages are intended to provide a variety of static configuration information, to assist in debugging problems that may be associated with particular configurations. For example, CONFIG message might include the CPU type, the graphics depth, the GUI look-and-feel, etc.
The CONFIG
works well for assisting system admins with the items listed above.
Typically INFO messages will be written to the console or its equivalent. So the INFO level should only be used for reasonably significant messages that will make sense to end users and system administrators.
Examples of this are tracing program startup and shutdown.
In general WARNING messages should describe events that will be of interest to end users or system managers, or which indicate potential problems.
An example use case could be exceptions thrown from AutoCloseable.close implementations.
In general SEVERE messages should describe events that are of considerable importance and which will prevent normal program execution. They should be reasonably intelligible to end users and to system administrators.
For example, if you have transaction in your program where if any one of the steps fail then all of the steps voided then SEVERE would be appropriate to use as the log level.