59°

log4j2.xml 配置样例

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="off">

<Properties> <Property name="LOG_HOME">/home/lbyw/logs</Property> <Property name="LOG_NAME">shou</Property> <Property name="LOG_PATTERN">%d|1771|shou||%p||%c|%m|%t||||%ex%n</Property> </Properties>

<Appenders> <!--commented by ysma <Syslog name="appender1" format="RFC5424" host="10.40.16.62" port="515" protocol="TCP" appName="shou1771" messageId="shou" facility="LOCAL2" newLine="true" mdcId="mdc" includeMDC="true" newLineEscape="#NewLine#" exceptionPattern="%ex" immediateFlush="false" connectTimeoutMillis="3000" reconnectionDelayMillis="3000"> <LoggerFields> <KeyValuePair key="syslogk1" value="%l"/> <KeyValuePair key="syslogk2" value="%X{syslogk2}"/> <KeyValuePair key="syslogk3" value="%X{syslogk3}"/> <KeyValuePair key="syslogk4" value="%X{syslogk4}"/> <KeyValuePair key="syslogk5" value="%X{syslogk5}"/> </LoggerFields> </Syslog>-->

<Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="${LOG_PATTERN}"/> </Console>

<!-- DEBUG日志格式 --> <RollingFile name="shou_debug_appender" fileName="${LOG_HOME}/${LOG_NAME}-debug.log" filePattern="${LOG_HOME}/${LOG_NAME}-debug.log.%d{yyyy-MM-dd}-%i.gz" append="true" immediateFlush="true"> <Filters> <!-- 控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch) --> <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/> </Filters> <PatternLayout> <pattern>${LOG_PATTERN}</pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy interval="1" modulate="true"/> <SizeBasedTriggeringPolicy size="500 MB"/> </Policies> <DefaultRolloverStrategy max="7"/> </RollingFile>

<!-- INFO日志格式 --> <RollingFile name="shou_info_appender" fileName="${LOG_HOME}/${LOG_NAME}-info.log" filePattern="${LOG_HOME}/${LOG_NAME}-info.log.%d{yyyy-MM-dd}-%i.gz" append="true" immediateFlush="true"> <Filters> <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/> </Filters> <PatternLayout> <pattern>${LOG_PATTERN}</pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy interval="1" modulate="true"/> <SizeBasedTriggeringPolicy size="500 MB"/> </Policies> <DefaultRolloverStrategy max="7"/> </RollingFile>

<!-- ERROR日志格式 --> <RollingFile name="shou_error_appender" fileName="${LOG_HOME}/${LOG_NAME}-error.log" filePattern="${LOG_HOME}/${LOG_NAME}-error.log.%d{yyyy-MM-dd}-%i.gz" append="true" immediateFlush="true"> <Filters> <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/> </Filters> <PatternLayout> <pattern>${LOG_PATTERN}</pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy interval="1" modulate="true"/> <SizeBasedTriggeringPolicy size="500 MB"/> </Policies> <DefaultRolloverStrategy max="7"/> </RollingFile>

</Appenders> <Loggers> <!-- 配置日志的根节点 --> <Root level="DEBUG"> <AppenderRef ref="shou_debug_appender" /> <AppenderRef ref="shou_info_appender" /> <AppenderRef ref="shou_error_appender" /> </Root>

<!-- 第三方日志系统 --> <Logger name="com.esup" level="INFO"/> <Logger name="com.shou" level="INFO" /> <logger name="org.springframework" level="INFO"/> <logger name="java.sql" level="info" /> </Loggers> </Configuration>

本文由【重城重楼】发布于开源中国,原文链接:https://my.oschina.net/ysma1987/blog/3073245

全部评论: 0

    我有话说: