I. Overview
Spring-boot supports log at info level by default.
Log levels: Trace, debug, info, warn, error, fatal, off "off"
II. Configuration Log level 2.1, configuration file configuration log level
Add in Application.properties
# logging.level.* where * means package name or class name root represents all Logging.level.root=debug
Ability to print out Spring-boot logs, as well as user-defined logs
Specify a class or package, others do not specify the use of the default info level
Logging.level.com.lhx.spring.springboot.service.userservice=debuglogging.level.com.lhx.spring.springboot.dao.userdao=debug
2.2, start parameter increase start parameter
--debug
Ability to print out Spring-boot log, cannot print user custom
2.3. In the Code
Configurableapplicationcontext context = Springapplication.run (App.class, "--debug=true");
Ability to print out Spring-boot log, cannot print user custom
Third, file output 1, configure the specified directory output
Logging.file=e:/tmp/my.log
2. Configure log directory "at this time log name Spring.log"
Logging.path=e:/tmp/logs
The above two, log file output, file size 10M, automatic segmentation
Iv. output Format 4.1, console and file pattern
logging.pattern.console=%-(%d{yyyy-mm-dd} [%thread])%-5level%logger{-%msg% Nlogging. file. console=%-(%d{yyyy-mm-dd HH:mm:ss. SSS} [%thread])%-5level%logger{}-%msg%n
Five, spring log Analysis 5.1, the default native
See Spring-boot using Logback to output log files
Add Logback.xml or Logback-spring.xml (spring recommended) files to the resources below
<?XML version= "1.0" encoding= "UTF-8"?><Configuration> <Appendername= "ConsoleLog"class= "Ch.qos.logback.core.ConsoleAppender"> <Layout> <pattern>%-20 (%d{yyyy-mm-dd HH:mm:ss. SSS} [%thread])%-5level%logger{80}-%msg%n</pattern> </Layout> </Appender> <Root Level= "DEBUG"> <Appender-refref= "ConsoleLog" /> </Root></Configuration>
5.2. Replace Log4j2
Among the use of Spring-boot-starter
< Dependency > < groupId >org.springframework.boot</groupId> < Artifactid>spring-boot-starter</artifactid> </ Dependency >
A log reference has been added by default and should be excluded first
<Dependency> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-starter</Artifactid> <Exclusions> <exclusion> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-starter-logging</Artifactid> </exclusion> </Exclusions> </Dependency>
Add Log4j2.pom Configuration
< Dependency > < groupId >org.springframework.boot</groupId> < Artifactid>spring-boot-starter-log4j2</artifactid> </dependency>
Add Log4j2.xml log4j2-spring.xml (Spring recommended) profile
<?XML version= "1.0" encoding= "UTF-8"?><Configuration> <appenders> <Consolename= "Console"Target= "System_out"Follow= "true"> <Patternlayoutpattern= "%d{yyyy-mm-dd HH:mm:ss. SSS} [%thread]%-5level%logger{80}-%msg%n " /> </Console> </appenders> <Loggers> <Root Level= "DEBUG"> <Appender-refref= "Console" /> </Root> </Loggers></Configuration>
Programs can be used
5.3. Related source code
View the Spring-boot-1.5.9.release.jar package to view support for the following four types of
Org.springframework.boot.loggingorg.springframework.boot.logging.javaorg.springframework.boot.logging.log4j2org.springfra Mework.boot.logging.logback
View the log level in org.springframework.boot.logging Org.springframework.boot.logging.LogLevel
Public enum LogLevel { TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF}
Configuration items in: Org.springframework.boot.logging.LoggingSystemProperties class
In Org.springframework.boot.logging.logback, view Default.xml, Base.xml, File-appender.xml, console-appender.xml profiles
019-spring Boot Log