Detailed explanation about Spring Boot's log management
Preface
Spring Boot uses Commons Logging in all internal logs , but the default configuration also provides support for commonly used 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
- Separator ― ― Identifies the start of the actual log
- Thread name ― enclosed in square brackets (may truncate console output)
- Logger name ― Normally Use the class name of the source code
- Log content
Console outputTFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
In Spring Boot, ERROR, WARN, and INFO level logs are configured by default to be output to the console.TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
We can switch to DEBUG level in two ways:TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
$ java -jar myapp.jar debug TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
application.properties
debug=true, when this property is set to true, the core Logger (including embedded containers, hibernate, spring) will output more content, but your own application logs will not be output at DEBUG level.
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
Colorful OutputTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
If your terminal supports ANSI, setting colored output will make the logs more readable. Supported by setting thespring.output.ansi.enabled parameter in
application.properties.
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Net - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
File OutputTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
The default configuration of Spring Boot will only be output to the console and will not be recorded in a file. However, we usually need to record it in a file when using it in a production environment.TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
To increase file output, you need to configurelogging.file or in
application.properties
logging.pathProperty.
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
logging.file, set the file, which can be an absolute path or a relative path. For example:
logging.file=my.logTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
logging.path, set the directory, the
spring.log file will be created in the directory, and the log content will be written, such as:
logging.path =/var/logTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
Level ControlTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
In Spring Boot, you only need to configure it inapplication.properties to complete the level control of logging.
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
logging.level.*=LEVELTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
1.logging.level
: Log level control prefix, * is the package name or Logger name
2.LEVEL: Options TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
Example:
##logging .level.com.juzi=DEBUG com.juziAll classes under the package are output at DEBUG level
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
logging.level.root=WARN The root log is output at WARN level
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
Custom log configurationTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
Since the log service is generally initialized before the ApplicationContext is created, it does not have to pass Spring configuration file control.TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network Therefore, log control and management can still be well supported through system properties and traditional Spring Boot external configuration files.
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
1.Logback: logback-spring.xml, logback-spring.groovy, logback.xml, logback.groovy logback log configurationTFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network##TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
4.JDK (Java Util Logging ): logging.properties
Spring Boot official recommendation is to give priority to the file name with -spring as your log configuration (such as using logback-spring .xml, not logback.xml)
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning NetworkCustomized output format
TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning NetworkIn Spring Boot, you can control the output format by configuring the following parameters in
application.properties: TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
1.
: Define the style of output to the console (JDK Logger is not supported)TFhHTML5 Chinese Learning Network-HTML5 Pioneer Learning Network
TFhHTML5 Chinese Learning Network - HTML5 Pioneer Learning Network
2.
: Define the style of output to the file (JDK Logger is not supported)
The above is the detailed content of Detailed explanation about Spring Boot's log management. 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.

When we use the win10 system, when we use the mouse to right-click the desktop or the right-click menu, we find that the menu cannot be opened and we cannot use the computer normally. At this time, we need to restore the system to solve the problem. Win10 right-click menu management cannot be opened: 1. First open our control panel, and then click. 2. Then click under Security and Maintenance. 3. Click on the right to restore the system. 4. If it still cannot be used, check whether there is something wrong with the mouse itself. 5. If you are sure there is no problem with the mouse, press + and enter. 6. After the execution is completed, restart the computer.

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.

JUnit is a widely used Java unit testing framework in Spring projects and can be applied by following steps: Add JUnit dependency: org.junit.jupiterjunit-jupiter5.8.1test Write test cases: Use @ExtendWith(SpringExtension.class) to enable extension, use @Autowired inject beans, use @BeforeEach and @AfterEach to prepare and clean, and mark test methods with @Test.

In back-end management systems, access permission control is usually required to limit different users' ability to access interfaces. If a user lacks specific permissions, he or she cannot access certain interfaces. This article will use the waynboot-mall project as an example to introduce how common back-end management systems introduce the permission control framework SpringSecurity. The outline is as follows: waynboot-mall project address: https://github.com/wayn111/waynboot-mall 1. What is SpringSecurity? SpringSecurity is an open source project based on the Spring framework, aiming to provide powerful and flexible security for Java applications.
