当前位置:网站首页>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的小技巧。
- 2022第六季完美童模 IPA国民赛领跑元宇宙赛道
- What problems will you encounter when dialing VPS?
- How to call out services in idea and display the startup class in services
- Virtual serial port function of j-link V9 using skills
- 中金财富是国企吗,开户安全吗
- Question bank and online simulation examination for safety management personnel of hazardous chemical business units in 2022
- What is a boolean type?
- Is the availability of proxy IP equal to the efficiency of proxy IP?
- 如何对代理IP进行分类?
猜你喜欢

MySQL basic record

紫光国微财报一枝独秀 2021年净利润三位数增长靠什么

A simple and open source navigation website source code

Cc2541 emulator CC debugger tutorial

Introduction to esp32 Bluetooth controller API

腾讯云接口进行人脸检测 和签名出错问题

Shardingsphere read write separation

Question bank and online simulation examination for safety management personnel of hazardous chemical business units in 2022

Digital collection platform settled in digital collection platform to develop SaaS platform of digital collection

Is the availability of proxy IP equal to the efficiency of proxy IP?
随机推荐
一些使用代理IP的小技巧。
About how to import C4d animation into lumion
Shardingsphere read write separation
Challenges often faced by client project management
2022.4.20-----leetcode.388
代理IP可用率是不是等同于代理IP的效率?
C语言实现Base64编码/解码
Makefile文件是什么?
NPM -- configure Taobao image
keil mdk中文乱码,两种解决方法,字体不再难看
Realize linear regression with tensorflow (including problems and solutions in the process)
腾讯云接口进行人脸检测 和签名出错问题
2022 low voltage electrician examination questions and answers
有哪些常见的代理ip问题?
如何设置电脑ip?
Do447 manage user and team access
Question bank and online simulation examination for safety management personnel of hazardous chemical business units in 2022
中金财富跟中金公司是一家公司吗,安全吗
How to "gracefully" measure system performance
Batch multiple files into one hex