当前位置:网站首页>Log4j2 configuration
Log4j2 configuration
2022-04-23 02:02:00 【Borrow another 500 years from heaven】
log4j2 To configure
Log output format :
%-5level Level
%d{yyy-MM-dd HH:mm:ss.SSS} date
%c Full name of current class
%M Current execution method
%L Line number
%t The thread of
%m Information
%n Line break
log4j2.xml Example 1
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<properties>
<property name="logDir">D:/0000/logs</property>
</properties>
<Appenders>
<!-- Console -->
<Console name="consoleAppender" target="SYSTEM_ERR">
<!--pattern: date , The thread of , The level of logging , Log name , Log information , Line break -->
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%t] %c.%M[%L] - %m%n" />
</Console>
<!-- file -->
<File name="fileAppender" fileName="${logDir}//log4j2.log">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%t] %c.%M[%L] - %m%n" />
</File>
<!-- Split logs according to format -->
<RollingFile name="rollingFile"
fileName="${logDir}/rollog.log"
filePattern="${logDir}/rollog_-%d{yyyyMMdd}-%i">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%t] %c.%M[%L] - %m%n" />
<Policies>
<!-- Startup time , Penalty splitting rules , Generate a log file -->
<OnStartupTriggeringPolicy />
<!-- Split by size -->
<SizeBasedTriggeringPolicy size="10kb" />
<!-- Split according to the time node , Split rules filePattern -->
<TimeBasedTriggeringPolicy />
</Policies>
<!-- In the same directory , Maximum number of files , Override if exceeded -->
<DefaultRooloverStrategy max="3" />
</RollingFile>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="consoleAppender" />
<!-- <AppenderRef ref="fileAppender" /> -->
<AppenderRef ref="rollingFile" />
</Root>
</Loggers>
</Configuration>
log4j2.xml Example 2
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="warn">
<Properties>
<!-- Configure the log file output directory , This configuration outputs logs to tomcat The specified folder under the root directory -->
<Property name="LOG_HOME">logs</Property>
<!-- Log output format -->
<Property name="LOG_PATTERNLAYOUT">[SysLog] [%p] [%d{yyyy-MM-dd HH:mm:ss}] [%l] : %m%n</Property>
</Properties>
<Appenders>
<!-- Console output only level And above (onMatch), Other direct rejection (onMismatch), Currently only output TRACE,DEBUG,INFO Three -->
<!-- Format of output log -->
<Console name="console_out_appender" target="SYSTEM_OUT">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERNLAYOUT}"/>
</Console>
<!-- INFO The level of log -->
<RollingRandomAccessFile name="info_appender" immediateFlush="true" fileName="${LOG_HOME}/sys.log"
filePattern="${LOG_HOME}/sys.log.%d{yyyy-MM-dd}">
<PatternLayout pattern="${LOG_PATTERNLAYOUT}"/>
<Policies>
<!-- <SizeBasedTriggeringPolicy size="2MB"/>-->
<!-- If you enable this configuration , The log will generate a new compressed file by file name , That is, if filePattern The date format configured is %d{yyyy-MM-dd HH}
, A compressed file is generated every hour , If filePattern The date format configured is %d{yyyy-MM-dd} , It's a compressed file -->
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${LOG_HOME}" maxDepth="1">
<IfFileName glob="*.log.*"/>
<IfLastModified age="3d"/>
<!--!Note: there age It has to be with filePattern Coordinate ,
The latter is accurate to HH, This is going to be written as xH, xd It doesn't work , Accurate to mm The following is the component unit 4320 yes 3 Days of ,
Time needs to ensure that the file is not occupied, otherwise it may be deleted , The most recent file is still occupied , Result in unsuccessful deletion !-->
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<!-- Configure the root node of the log -->
<root level="INFO">
<appender-ref ref="console_out_appender"/>
<appender-ref ref="info_appender"/>
</root>
<!-- Third party logging system , For... Under the specified package class Specify different log levels -->
<!-- <logger name="org.springframework.core" level="warn"/>-->
<!-- <logger name="org.springframework.beans" level="warn"/>-->
<!-- <logger name="org.springframework.context" level="warn"/>-->
<!-- <logger name="org.springframework.web" level="warn"/>-->
<!-- <logger name="org.jboss.netty" level="warn"/>-->
<!-- <logger name="org.apache.http" level="warn"/>-->
</Loggers>
</configuration>
版权声明
本文为[Borrow another 500 years from heaven]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220843483379.html
边栏推荐
- 在使用代理IP前需要了解哪些分类?
- Find the largest number of two-dimensional arrays
- 2022第六季完美童模 IPA國民賽領跑元宇宙賽道
- Introduction to esp32 Bluetooth controller API
- What are the test steps of dynamic proxy IP?
- A simple and open source navigation website source code
- Analyze the three functions of static proxy IP.
- 搭建网站是用物理机还是云主机好?
- Server 2019 the available memory of the server is half of the actual memory
- Keil MDK Chinese garbled code, two solutions, the font is no longer ugly
猜你喜欢
What business scenarios will the BGP server be used in?
BGP服务器在什么业务场景会被用到?
2022 crane driver (limited to bridge crane) examination question bank and online simulation examination
如何“优雅”的测量系统性能
批处理多个文件合成一个HEX
W801 / w800 WiFi socket development (II) - UDP Bluetooth control WiFi connection
Introduction to esp32 Bluetooth controller API
The leader / teacher asks to fill in the EXCEL form document. How to edit the word / Excel file on the mobile phone and fill in the Excel / word electronic document?
Use Xdebug breakpoint debugging in postman
《维C中国》乡村助农暖人心第三站嘉宝果农场
随机推荐
W801 / w800 WiFi socket development (II) - UDP Bluetooth control WiFi connection
Campus transfer second-hand market source code
PID精讲
Chinese scientists reveal a new mechanism for breaking through the bottleneck of rice yield
简洁开源的一款导航网站源码
What business scenarios will the BGP server be used in?
Makefile文件是什么?
Is the availability of proxy IP equal to the efficiency of proxy IP?
[leetcode daily question] 396 Rotation function
世界读书日 | 技术人不要错过的好书(IT前沿技术)
Shardingsphere broadcast table and binding table
腾讯云接口进行人脸检测 和签名出错问题
How can e-procurement become a value-added function in the supply chain?
什么是bgp服务器,有哪些优势?
什么是api接口?
Sqlserver data transfer to MySQL
Is it better to use a physical machine or a virtual machine to build a website?
2018 China Collegiate Programming Contest - Guilin Site J. stone game
Unicorn bio raised $3.2 million to turn prototype equipment used to grow meat into commercial products
Performance introduction of the first new version of cdr2022