Different Log Levels in SLF4j

There are different ways to log messages, in order of fatality:
  1. ERROR
  2. WARN
  3. INFO
  4. DEBUG
  5. TRACE

Common levels
LevelDescription
ERROROther runtime errors or unexpected conditions. Expect these to be immediately visible on a status console.
WARNO
INFOInteresting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum.
DEBUGdetailed information on the flow through the system. Expect these to be written to logs only.
TRACEmore detailed information. Expect these to be written to logs only.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class Log4jExample {
 
    private static Logger logger = LoggerFactory.getLogger(Log4jExample.class);
 
    public static void main(String[] args) {
        logger.trace("Trace log message");       
  logger.debug("Debug log message");
        logger.info("Info log message");
        logger.warn("Warning log message");        
logger.error("Error log message");
    }
}
if INFO is set then output:

2018-06-16 17:02:13 INFO  Info log message
2018-06-16 17:02:13 WARN Warning log message
2018-06-16 17:02:13 ERROR Error log message

if trace is set:
2018-06-16 17:02:13 TRACE Trace log message
2018-06-16 17:02:13 DEBUG Debug log message
2018-06-16 17:02:13 INFO  Info log message
2018-06-16 17:02:13 WARN Warning log message
2018-06-16 17:02:13 ERROR Error log message

Comments