background

Java logging in two aspects, one is the logging framework, one is the framework, the appearance of the logging framework is used to output a log, a class is used to provide an appearance, makes a written (i.e., with one line of code) can call a different framework, depending on how you configure it, what kind of configuration, specific use which kind of framework, The facade class itself does not log, it just calls the logging framework to log.

The design pattern used here is facade, where facade classes provide a unified interface and can be switched between the logging framework implemented without changing the log printing code.

The logging framework

Log4j logback is the latest version of log4j

An updated version of Log4j that is faster than log4j, SpringBoot uses LogBack by default.

The facade class

slf

How does it work in code?

package com.wz.bpm;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

@SpringBootApplication
@MapperScan("com.wz.bpm.mapper") @EnableCaching public class BpmMainApplication { private static Logger logger = LoggerFactory.getLogger(BpmMainApplication.class); // All the logging classes in this line of code are facade framework classes, so switch the logging framework, the code here does not change. public static void main(String[] args) { logger.info("Server started..."); SpringApplication.run(BpmMainApplication.class, args); }}Copy the code

The output

15:15:15. [the main] INFO 765 com. Wz. BPM. BpmMainApplication - the server to start...Copy the code

reference

Tengj. Top / 2017/04/05 /… // Very well written