Simple Logging Facade for Java (SLF4J)
July 6, 2010 Leave a comment
The Simple Logging Facade for Java or (SLF4J) serves as a simple facade or abstraction for various logging frameworks, e.g. java.util.logging, log4j and logback, allowing the end user to plug in the desired logging framework at deployment time.
Before you start using SLF4J, we highly recommend that you read the two-page SLF4J user manual.
In case you wish to migrate your Java source files to SLF4J, consider our migrator tool which can migrate your project into SLF4J in minutes.
In case an externally-maintained component you depend on uses a logging API other than SLF4J, such as commons logging, log4j or j.u.l, have a look at SLF4J’s binary-support for legacy APIs.
Why doesn’t the
org.slf4j.Loggerinterface have methods for the FATAL level?
From the stand point of a logging system, the distinction between a fatal error and an error is usually not very useful. Most programmers exit the application when a fatal error is encountered. However, a logging library cannot (and should not) decide on its own to terminate an application. The initiative to exit the application must be left to the developer.
Thus, the most the FATAL level can do is to highlight a given error as the cause for application to crash. However, errors are by definition exceptional events that merit attention. If a given situation causes errors to be logged, the causes should be attended to as soon as possible. However, if the “error” is actually a normal situation which cannot be prevented but merits being aware of, then it should be marked as WARN, not ERROR.
Assuming the ERROR level designates exceptional situations meriting close attention, we are inclined to believe that the FATAL level is superfluous.
I am not sure I buy their argument though, I had a number of fatal events logged in my code which would cause instant termination. Usually this because of missing configuration files, missing directories, failure to connect to a service to get vital information, stuff like that. I renamed them to errors and changed the message to be a little more urgent in tone.