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 write the code for springboot2.0 to integrate logback logs

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to write the code of springboot2.0 integration logback log". In the daily operation, I believe that many people have doubts about how to write the code of springboot2.0 integration logback log. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to write the code of springboot2.0 integration logback log". Next, please follow the editor to study!

Springboot's pom file will quote a parent.

Org.springframework.boot spring-boot-starter-parent 2.0.0.RELEASE

If you click on this parent, you will have a dependency.

Org.springframework.boot spring-boot-dependencies 2.0.0.RELEASE.. /.. / spring-boot-dependencies

Click on version 2.0, which gives you various integrated package dependencies and specifies the version number, one of which is as follows

Org.springframework.boot spring-boot-starter 2.0.0.RELEASE

Click in again.

Org.springframework.boot spring-boot-starter-logging 2.0.0.RELEASE compile

Again, these are the original log packages, so you don't have to rely on them any more and just use ok. The usage is as follows:

Ch.qos.logback logback-classic 1.2.3 compile org.apache.logging.log4j log4j-to-slf4j 2.10.0 compile org.slf4j jul-to-slf4j 1.7.25 compile

= = split line =

First of all, the official recommended format for the xml name is: logback-spring.xml instead of logback.xml, as to why, because people with the spring suffix can use this tag.

Create a logback-spring.xml file under resource

The content is as follows, with comments on each line.

Logback info ${CONSOLE_LOG_PATTERN} UTF-8 ${log.path} / log_debug.log% d {yyyy-MM -dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n UTF-8 ${log.path} / debug/log-debug-%d {yyyy-MM-dd}.% i.log 100MB 15 Debug ACCEPT DENY ${log.path} / log_info.log ${log.path} / info/log-info-%d {yyyy-MM-dd}.% i.log ${log.path} / log_warn.log UTF-8 ${log.path} / warn/log-warn-%d {yyyy-MM-dd}.% i.log warn ${log.path} / log_error.log ${log.path} / error/log-error-%d {yyyy-MM-dd}. When i.log ERROR uses mybatis The sql statement is printed only under debug, but here we only configure info, so if you want to view the sql statement, there are two operations: first, changing it to this way will print sql, but there will be a lot of other messages there. The second is to configure debug mode for the directory under dao separately. The code is as follows, so that the configuration sql statement will print. The other is the normal info level:-- > root node is a required node to specify the most basic log output level. Only one level attribute cannot be set to INHERITED or the synonym NULL. The default is that DEBUG can contain zero or more elements, indicating that the appender will be added to the logger.

It is said that the color log function needs to download the plug-in and then configure it in yml or properties.

Logging.config=classpath:log/logback-spring.xmllogging.path=D:/nmyslog/nmys

Logs are used in the same way as usual, except that this configuration is configured to retain not only output on the console but also on disk, and info/debug/error/warn logs are distinguished and archived on a daily basis.

At this point, the study on "how to write the code for springboot2.0 to integrate logback logs" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Development

Wechat

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

12
Report