How to integrate logback Log Management in Springboot
How to integrate logback log management in Springboot, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1.spring-boot-starter\ spring-boot-starter-web supports logback by default, and file naming without introducing pom2.logback is officially recommended to read the configuration in the logback-spring.xml custom location application.yml under the resources directory by default: (logging.config: classpath:log/logback-spring.xml; logging.level.root: info)
3.logback profile
3.1 LOG_HOME catalina.base refers to a directory at the same level as the project parent directory
3.2 root.level specifies the log level
% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n ${LOG_HOME} / server.%d {yyyy-MM-dd} .log 30% d {yyyy-MM -dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n 10MB 4. How to use it in code
4.1Using @ slf4j annotations directly in classes and using log objects directly in code requires the introduction of lombok
Org.projectlomboklomboktrue
4.2 create an instance through loggerFactory
Import lombok.extern.slf4j.Slf4j;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping ("/ logback") / * 1. Introduce log instance * / @ Slf4jpublic class HelloController {/ * 2 through @ slf4j annotation. Create logger instance * / private final static Logger log= LoggerFactory.getLogger (HelloController.class) through loggerFacotory; @ RequestMapping ("/ showinfo") @ ResponseBody public String ShowInfo () {log.info ("hello!"); return "hello logback";}} 5. Block log
Configuration in application.properties
Close the log for com.zhl.springbootlogback:
Logging.level.com.zhl.springbootlogback=off has read the above, have you mastered how to integrate logback log management in Springboot? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!