Spring Boot Base Log configuration

Source: Internet
Author: User
Tags log log java util

Spring boot internally uses Commons Logging to log logs, but also retains the external interface for some log frameworks to implement, such as Java Util logging,log4j2 and Logback. If you want to use a certain log framework for implementation, you must first configure, by default, spring boot uses logback as the framework for log implementations.

1. Configure the debug level of the console log

By default, the log level that spring boot prints from the console is only error, WARN also has info, and if you want to print debug-level logs, you can configure it through Application.properites debug=true

Debug=true

In a production environment, you can configure the debug level of the log through the command line

Java-jar C:\Users\Administrator\Desktop\xx\demo.jar--debug

3. Configure logging.level.* to specifically output which package's log level

Logging.level.root=info
logging.level.org.springframework.web=debug
logging.level.org.hibernate=error

2. Output the log to a file

Spring boot does not output the log to the log file by default, but you can output the log to a file by configuring the Logging.file file name and the Logging.path file path in the Application.properites file

Logging.path=f:\\demo
logging.file=demo.log
logging.level.root=info

Here are a few things to note: If you do not configure the specific package log level, the log file information will be empty if you configure only Logging.path, a log file will be generated in the F:\demo folder for Spring.log To configure Logging.file only, a demo.log log file will be generated under the project's current path Logging.path and Logging.file are configured simultaneously, and there will be no F:\demo\ on this path Demo.log log generation, Logging.path and logging.file do not stack Logging.path and logging.file value can be relative or absolute

This is the basic log configuration, which can be configured directly in the Application.properties, and we can also configure it under the Classpath path by defining a specific log file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.