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 solve the error report of springboot Integration log4j

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the relevant knowledge of "springboot integration log4j error reporting how to solve", the editor shows you the operation process through the actual case, the operation method is simple, fast and practical. I hope this "springboot integration log4j error reporting how to solve" article can help you solve the problem.

1. Add 1.1, add dependencies

You need to introduce dependency support for log4j, and recommend which version to use.

Org.apache.logging.log4j log4j-to-slf4j 2.11.21.2, eliminate dependencies

By default, springboot has added internal support for logs, and you need to eliminate all of them, otherwise it will affect the dependent use of log4j.

Org.springframework.boot spring-boot-starter-logging * * 2, configuration log 2.1, log print record

  carries on the relevant configuration according to its own needs. What you need to note here is to use the xml file for configuration, whether to use properties to get up or not, and the file name is customized. There are no requirements, which will be specified in the configuration file.

Beordie info ${CONSOLE_LOG_PATTERN} UTF-8 ${path} / debug.log% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n UTF-8 ${log} / debug/log-debug-%d {yyyy-MM-dd}.% i.log 100MB 15 debug ACCEPT DENY ${log} / info.log % d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n UTF-8 ${log} / info/log-info-%d {yyyy-MM-dd}.% i.log 100MB 15 Info ACCEPT DENY ${log} / warn.log% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n UTF-8 ${log} / warn/log-warn-% D {yyyy-MM-dd}.% i.log 100MB 15 warn ACCEPT DENY ${log} / error.log% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% Logger {50} -% msg%n UTF-8 ${log} / error/log-error-%d {yyyy-MM-dd}.% i.log 100MB 15 ERROR ACCEPT DENY 2.2 、 Specify profile

You also need to specify the configuration in the project configuration file of spring boot.

Logging: config: classpath:log4j.xml

Complete the overall configuration of the log here, and the startup project can print the log by getting the log object through the following statement.

Private final Logger LOGGING = LoggerFactory.getLogger (ArticleController.class); add: log4j tuning and precautions

Log mode-synchronous / asynchronous

Log4j2 provides AsyncAppender and AsyncLogger, as well as global async, which is enabled as follows:

Synchronous mode: the default configuration is synchronous mode, that is, no AsyncAppender and AsyncLogger are used.

Global asynchrony: the configuration is configured in a synchronous manner. You can enable global asynchrony by adding jvm startup parameters without modifying the configuration and application.

Hybrid async: use a hybrid configuration of asynchronous Logger and synchronous Logger, and do not enable global async, that is, part AsyncLogger and part Logger in Logger configuration.

Considerations for using log mode:

If async is used, it is recommended that you use the AsyncLogger implementation instead of AsyncAppender.

If synchronization is used, AsyncLogger, AsyncAppender, and global async can only be used, AsyncAppender and AsyncLogger cannot be configured at the same time, or global async is enabled if async is configured.

Log scrolling and cleanup policy

Log4j2 provides file size-based scrolling strategy and time-based scrolling strategy, or both. Here, size-based scrolling policy configuration and size / time-based double scrolling policy configuration are given:

Size-based scrolling strategy: scroll by size, enable compression, and retain up to N files

Based on the size / time double scrolling strategy: scroll by size and time, enable compression, control the maximum number of logs retained per unit time, and control the total log retention time.

This is the end of the content about "how to solve the error report of springboot Integration log4j". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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