In-depth understanding of Spring Boot's log management detailed introduction
This article mainly gives you an in-depth introduction to the relevant information of Spring Boot log management. The introduction in the article is very detailed. Friends in need can refer to it. Let’s take a look together.
Preface
Spring Boot uses Commons Logging in all internal logs, but the default configuration also provides support for common logs,
such as: Java Util Logging , Log4J, Log4J2 and Logback. Each Logger can be configured to use the console or file to output log content.
Log output format
2016-08-19 10:22:04.233 INFO 7368 --- [ main] com.juzi.AsyncTest : Started AsyncTest in 10.084 seconds (JVM running for 12.545)
The output content elements are as follows:
Time and date—accurate to milliseconds
Log level — ERROR, WARN, INFO, DEBUG or TRACE
Process ID
Delimiter — identifies the start of the actual log
Thread name — enclosed in square brackets (may truncate console output)
Logger name - usually use the class name of the source code
Log content
##Console output
In Spring Boot, ERROR, WARN, and INFO level logs are configured to be output to the console by default. We can switch to DEBUG level in two ways:$ java -jar myapp.jar – debug
## 2. Configure
in application.properties
. When this property is set to true, the core Logger (including embedded container, hibernate, spring) will output more content, but the logs of your own application will not be output to DEBUG level.
If your terminal supports ANSI, setting colored output will make the log more readable. Supported by setting the
spring.output.ansi.enabled parameter in application.properties
. 1.NEVER: Disable ANSI-colored output (default option)
2.DETECT: Check whether the terminal supports ANSI, if so, use colored output (recommended option)
3.ALWAYS: Always use ANSI-colored format output. If the terminal does not support it, there will be a lot of interference information. It is not recommended to use
Spring Boot's default configuration will only be output to the console and will not be recorded in a file, but we usually need to record it in a file when using it in a production environment.
To increase file output, you need to configure the
logging.file or logging.path
property in application.properties
. 1.
, set the file, which can be an absolute path or a relative path. For example: logging.file=my.log
2.
, set the directory, spring will be created in this directory. log
file, and write the log content, such as: logging.path=/var/log
The log file will be truncated when the size is 10Mb, and a new log file will be generated. , the default levels are: ERROR, WARN, INFO *
In Spring Boot, you only need to configure it in
application.properties Complete logging level control. Configuration format:
1.
: Log level control prefix, * is the package name or Logger name
2.LEVEL: Options TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
Example:
All classes under the package are output at DEBUG level
The root log is output at WARN level
Since the log service is generally initialized before the ApplicationContext is created, it does not have to be controlled through Spring's configuration file.
Therefore, log control and management can still be well supported through system properties and traditional Spring Boot external configuration files.
According to different log systems, you can organize the configuration file name according to the following rules, and it will be loaded correctly:
1.Logback:logback-spring.xml, logback-spring.groovy, logback.xml, logback.groovy logback日志配置 2.Log4j:log4j-spring.properties, log4j-spring.xml, log4j.properties, log4j.xml 3.Log4j2:log4j2-spring.xml, log4j2.xml 4.JDK (Java Util Logging):logging.properties
Spring Boot officially recommends using file names with -spring as your Log configuration (such as using logback-spring.xml instead of logback.xml)
Customized output formatIn Spring Boot you can pass in
application.propertiesConfigure the following parameters to control the output format: 1.
: Define the style of output to the console (JDK Logger is not supported)
2.
: Define the style of output to the file (JDK Logger is not supported)
The above is the detailed content of In-depth understanding of Spring Boot's log management detailed introduction. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics


![Windows ISO file too large BootCamp error [Fixed]](https://img.php.cn/upload/article/000/887/227/170831702395455.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
If you get the error message "The Windows ISO file is too large" when using BootCampAssistant on a Mac computer, this may be because the ISO file size exceeds the limit supported by BootCampAssistant. The solution to this problem is to use other tools to compress the ISO file size to ensure that it can be processed in BootCamp Assistant. BootCampAssistant is a convenient tool provided by Apple for installing and running Windows operating system on Mac computers. It helps users set up a dual-boot system, allowing them to easily choose to use MacOS or Wind at startup

In 2023, AI technology has become a hot topic and has a huge impact on various industries, especially in the programming field. People are increasingly aware of the importance of AI technology, and the Spring community is no exception. With the continuous advancement of GenAI (General Artificial Intelligence) technology, it has become crucial and urgent to simplify the creation of applications with AI functions. Against this background, "SpringAI" emerged, aiming to simplify the process of developing AI functional applications, making it simple and intuitive and avoiding unnecessary complexity. Through "SpringAI", developers can more easily build applications with AI functions, making them easier to use and operate.

As an industry leader, Spring+AI provides leading solutions for various industries through its powerful, flexible API and advanced functions. In this topic, we will delve into the application examples of Spring+AI in various fields. Each case will show how Spring+AI meets specific needs, achieves goals, and extends these LESSONSLEARNED to a wider range of applications. I hope this topic can inspire you to understand and utilize the infinite possibilities of Spring+AI more deeply. The Spring framework has a history of more than 20 years in the field of software development, and it has been 10 years since the Spring Boot 1.0 version was released. Now, no one can dispute that Spring

How to implement spring programmatic transactions: 1. Use TransactionTemplate; 2. Use TransactionCallback and TransactionCallbackWithoutResult; 3. Use Transactional annotations; 4. Use TransactionTemplate in combination with @Transactional; 5. Customize the transaction manager.

With the update and iteration of technology, Java5.0 began to support annotations. As the leading framework in Java, spring has slowly begun to abandon xml configuration since it was updated to version 2.5, and more annotations are used to control the spring framework.

How to set the transaction isolation level in Spring: 1. Use the @Transactional annotation; 2. Set it in the Spring configuration file; 3. Use PlatformTransactionManager; 4. Set it in the Java configuration class. Detailed introduction: 1. Use the @Transactional annotation, add the @Transactional annotation to the class or method that requires transaction management, and set the isolation level in the attribute; 2. In the Spring configuration file, etc.

With the continuous development of software development, log management has become an indispensable part of the code development process. As a relatively complex programming language, C++ also requires log management during code development. This article will introduce the log management principles and specific implementation of C++ code, hoping to be helpful to readers. 1. Log management principles determine the log level. The log level represents the importance and urgency of the log information. In C++ development, log levels are divided into DEBUG, INFO, WARN, ERROR and F

How to use the Hyperf framework for log management Introduction: Hyerpf is a high-performance, highly flexible coroutine framework based on the PHP language, with rich components and functions. Log management is an essential part of any project. This article will introduce how to use the Hyperf framework for log management and provide specific code examples. 1. Install the Hyperf framework First, we need to install the Hyperf framework. It can be installed through Composer, open the command line tool and enter the following command
