Log4j - Logging Levels - Tutorialspoint
Log4j - Logging Levels - Tutorialspoint
The org.apache.log4j.Level levels. You can also define your custom levels by sub-classing the
Level class.
Level Description
ERROR Designates error events that might still allow the application to
continue running.
FATAL Designates very severe error events that will presumably lead the
application to abort.
OFF The highest possible rank and is intended to turn off logging.
import org.apache.log4j.*;
https://www.tutorialspoint.com/log4j/log4j_logging_levels.htm 1/3
05/03/2021 log4j - Logging Levels - Tutorialspoint
log.trace("Trace Message!");
log.debug("Debug Message!");
log.info("Info Message!");
log.warn("Warn Message!");
log.error("Error Message!");
log.fatal("Fatal Message!");
}
}
When you compile and run the LogClass program, it would generate the following result −
Warn Message!
Error Message!
Fatal Message!
log4j provides you configuration file based level setting which sets you free from changing the
source code when you want to change the debugging level.
Following is an example configuration file which would perform the same task as we did using
the log.setLevel(Level.WARN) method in the above example.
import org.apache.log4j.*;
log.trace("Trace Message!");
log.debug("Debug Message!");
log.info("Info Message!");
https://www.tutorialspoint.com/log4j/log4j_logging_levels.htm 2/3
05/03/2021 log4j - Logging Levels - Tutorialspoint
log.warn("Warn Message!");
log.error("Error Message!");
log.fatal("Fatal Message!");
}
}
Now compile and run the above program and you would get following result in
/usr/home/log4j/log.out file −
Warn Message!
Error Message!
Fatal Message!
https://www.tutorialspoint.com/log4j/log4j_logging_levels.htm 3/3