If you use starters(spring-boot-starter artifact in pom.xml), Logback is used for logging by default. This is because spring-boot-starter contains spring-boot-starter-logging.
Logging level
The logging levels are ERROR, WARN, INFO, DEBUG, or TRACE. Default is INFO so DEBUG and TRACE logs are not visible.
Controller to test Logging level
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
@RestController public class LoggingController { private static final Logger LOG = LoggerFactory.getLogger(LoggingController.class); // http://localhost:8080/log @RequestMapping("/log") public String log() { LOG.error("This is an error message."); LOG.warn("This is a warning message."); LOG.info("This is an info message."); LOG.debug("This is a debug message."); LOG.trace("This is a trace message."); return "foo"; } }
You can set logging level in application.properties file or using program arguments.
1
logging.level.root=info
or
1
logging.level.root=INFO
we can also pass log level via command line arguments
<!-- set default log level to be INFO --> <!-- Log Level: ALL < DEBUG < INFO < WARN < ERROR < FATAL --> <rootlevel="INFO"> <appender-refref="STDOUT" /> </root> </configuration>
Log4j
To use Log4j, we need to exclude spring-boot-starter-logging for all dependencies that uses spring-boot-starter-logging. Then add log4j2 dependency