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!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


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

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function