当前位置:网站首页>[log frame]
[log frame]
2022-07-29 10:08:00 【Zanzaner_】
List of articles
Log framework
SpringBoot: The bottom is Spring frame ,Spring The frame defaults to JCL;‘
SpringBoot choose SLF4j and logback;
Log usage
1、 The default configuration
SpringBoot By default, the log is configured for us ;
// Recorder
Logger logger = LoggerFactory.getLogger(getClass());
@Test
public void contextLoads() {
//System.out.println();
// Level of logging ;
// From low to high trace<debug<info<warn<error
// You can adjust the log level of the output ; Logs will only take effect at this level at a later high level
logger.trace(" This is a trace journal ...");
logger.debug(" This is a debug journal ...");
//SpringBoot The default is info Grade , Use if you don't specify a level SpringBoot Default specified level ;root Level
logger.info(" This is a info journal ...");
logger.warn(" This is a warn journal ...");
logger.error(" This is a error journal ...");
}
SpringBoot Modify the default configuration of the log :
logging.level.com.atguigu=trace
#logging.path=
# Do not specify the path to generate... Under the current project springboot.log journal
# You can specify the full path ;
#logging.file=G:/springboot.log
# Create... Under the root path of the current disk spring Folder and inside log Folder ; Use spring.log As the default file
logging.path=/spring/log
# The format of the log output in the console
logging.pattern.console=%d{
yyyy‐MM‐dd} [%thread] %‐5level %logger{
50} ‐ %msg%n
# Specify the format of log output in the file
logging.pattern.file=%d{
yyyy‐MM‐dd} === [%thread] === %‐5level === %logger{
50} ==== %msg%n
Specify the configuration
Drop the configuration file of each log framework to the classpath ;SpringBoot It doesn't use his default configuration logback.xml: Directly recognized by the log framework ;logback-spring.xml: The log framework does not directly load the log configuration items , from SpringBoot Parsing log configuration , have access to SpringBoot Advanced Profile function
logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- scan: When this property is set to true when , If the configuration file changes , Will be reloaded , The default value is true. scanPeriod: Set the time interval between changes in the monitoring profile , If no time unit is given , The default unit is milliseconds scan by true when , This property takes effect . The default time interval is 1 minute . debug: When this property is set to true when , Will print out logback Internal log information , Real-time view logback Running state . The default value is false. -->
<configuration scan="false" scanPeriod="60 seconds" debug="false">
<!-- Define the log root -->
<property name="LOG_HOME" value="/app/log" />
<!-- Define log file name -->
<property name="appName" value="atguigu-springboot"></property>
<!-- ch.qos.logback.core.ConsoleAppender Indicates console output -->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<!-- Log output format : %d Means date time , %thread Represents the thread name , %-5level: The level is shown from the left 5 Character width %logger{50} Express logger The longest name 50 Characters , Otherwise, divide by periods . %msg: Log message , %n Is a newline -->
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ----> [%thread] ---> %-5level %logger{50} - %msg%n</pattern>
<!--<springProfile name="dev"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} --–> [%thread] -–> %-5level %logger{50} - %msg%n</pattern> </springProfile> <springProfile name="!dev"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ==== [%thread] ==== %-5level %logger{50} - %msg%n</pattern> </springProfile>-->
</layout>
</appender>
<!-- Scroll record file , First log to the specified file , When a condition is met , Log to other files -->
<appender name="appLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- Specify the name of the log file -->
<file>${LOG_HOME}/${appName}.log</file>
<!-- When rolling happens , decision RollingFileAppender act , It involves moving and renaming files TimeBasedRollingPolicy: The most common rolling strategy , It makes rolling strategies based on time , Responsible for rolling as well as starting rolling . -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- The storage location and file name of the file generated during scrolling %d{yyyy-MM-dd}: Scroll through the logs by day %i: When the file size exceeds maxFileSize when , according to i Scroll through the files -->
<fileNamePattern>${LOG_HOME}/${appName}-%d{yyyy-MM-dd}-%i.log</fileNamePattern>
<!-- Optional nodes , Control the maximum number of archive files that are retained , Delete old files if the number exceeds . Suppose you set scrolling every day , And maxHistory yes 365, Save only recent 365 Days of documents , Delete old files before . Be careful , Deleting old files is , Directories created for archiving will also be deleted . -->
<MaxHistory>365</MaxHistory>
<!-- When the log file exceeds maxFileSize The designated size is , According to the above %i Scroll the log file Note the configuration here SizeBasedTriggeringPolicy Scrolling by file size is not possible , You have to configure timeBasedFileNamingAndTriggeringPolicy -->
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<!-- Log output format : -->
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [ %logger{50} : %line ] - %msg%n</pattern>
</layout>
</appender>
<!-- logger It is mainly used to store log objects , You can also define the log type 、 Level name: A match logger Type prefix , The first half of the bag level: Log level to log , Include TRACE < DEBUG < INFO < WARN < ERROR additivity: The function is to children-logger Whether to use rootLogger Configured appender For the output , false: Means only the current logger Of appender-ref,true: At present logger Of appender-ref and rootLogger Of appender-ref Are effective -->
<!-- hibernate logger -->
<logger name="com.atguigu" level="debug" />
<!-- Spring framework logger -->
<logger name="org.springframework" level="debug" additivity="false"></logger>
<!-- root And logger It's father son relationship , If there is no special definition, it defaults to root, Any class can only be associated with one logger Corresponding , Or defined logger, Or root, The key to judgment is to find this logger, And then judge this logger Of appender and level. -->
<root level="info">
<appender-ref ref="stdout" />
<appender-ref ref="appLogAppender" />
</root>
</configuration>
If you use logback.xml As log profile , And use profile function , There will be the following mistakes
no applicable action for [springProfile]
边栏推荐
- [C language] minesweeping (recursive expansion + marking function)
- Leetcode question brushing - sorting
- Correct posture and landing practice of R & D efficiency measurement (speech ppt sharing version)
- 最新翻译的官方PyTorch简易入门教程(PyTorch1.0版本)
- 《LOL》从代码上来说最难的是哪个英雄?
- div 水平排列
- 函数和数组
- English grammar_ Indefinite pronouns - Common Phrases
- ModuleNotFoundError: No module named ‘pywt‘解决方法
- 机器学习之逻辑回归(Logistics Regression)
猜你喜欢
![[wechat applet] interface generates customized homepage QR code](/img/9b/cccdb8ff6db61518402a27b94d0196.png)
[wechat applet] interface generates customized homepage QR code

"Focus on machines": Zhu Songchun's team built a two-way value alignment system between people and robots to solve major challenges in the field of human-computer cooperation

函数——(C游记)

i. Mx6ull driver development | 32 - manually write a virtual network card device
![[FPGA tutorial case 18] develop low delay open root calculation through ROM](/img/c3/02ce62fafb662d6b13aedde79e21fb.png)
[FPGA tutorial case 18] develop low delay open root calculation through ROM

Yin Yi: my learning and growth path

电竞入亚后,腾讯要做下一个“NBA赛事捕手”?

English语法_不定代词 - 常用短语

Pytest+allure generate test report

Function - (C travel notes)
随机推荐
SiC功率半导体产业高峰论坛成功举办
A little knowledge ~ miscellaneous notes on topics ~ a polymorphic problem
【论文阅读】Q-BERT: Hessian Based Ultra Low Precision Quantization of BERT
The function of that sentence
消费电子,冻死在夏天
【日志框架】
MySQL infrastructure: SQL query statement execution process
Function - (C travel notes)
Notes for Resume Writing
Div horizontal arrangement
My problem solving record 1: the @component annotation is used on the class. If you want to use the methods in this class, you can't directly new, but should use @autowired for injection, otherwise an
Orbslam2 installation test and summary of various problems
[C language] minesweeping (recursive expansion + marking function)
How big is the bandwidth of the Tiktok server for hundreds of millions of people to brush at the same time?
程序员脱离单身的一些建议
电竞入亚后,腾讯要做下一个“NBA赛事捕手”?
那句话的作用
通俗易懂讲解梯度下降法!
[C language] Sanzi chess (intelligent chess playing + blocking players)
【配置相关】