Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate logback Log Management in Springboot

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report