日志样例 :
2018-10-21 07:30:05,184 INFO - DeviceChannelServiceImpl.java:434[defaultEventExecutorGroup-2-24] - batchGet time:0 2018-10-21 07:30:05,191 ERROR - LechangeImplBussiness.java:96[defaultEventExecutorGroup-2-24] - ability error, did=4E01748YAG4A2AA, ability in channel=1, ability in device=
log4j2.xml 样例:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="info"> <!--先定义所有的appender--> <Appenders> <!--这个输出控制台的配置--> <Console name="Console" target="SYSTEM_OUT"> <!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)--> <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/> <!--这个都知道是输出日志的格式--> <!--<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>--> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %F:%L - %m%n"/> </Console> <!-- 异常信息打印--> <RollingRandomAccessFile name="Error" fileName="logs/error.log" filePattern="./logs/error.log.%i"> <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %F:%L[%t] - %m%n"/> <SizeBasedTriggeringPolicy size="200MB"/> <DefaultRolloverStrategy max="20" /> </RollingRandomAccessFile> <!--这个会打印出所有的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档--> <!-- <RollingRandomAccessFile name="RollingFile" fileName="./logs/ads.log" filePattern="./logs/$${date:yyyy-MM}/ads-%d{MM-dd-yyyy}-%i.log.gz">--> <RollingRandomAccessFile name="RollingFile" fileName="./logs/server.log" filePattern="./logs/server.log.%i"> <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %F:%L[%t] - %m%n"/> <SizeBasedTriggeringPolicy size="200MB"/> <DefaultRolloverStrategy max="20" /> </RollingRandomAccessFile> </Appenders> <!--然后定义logger,只有定义了logger并引入的appender,appender才会生效--> <Loggers> <Logger name="org.springframework" level="info" additivity="false"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Logger> <Logger name="com.dahua" level="info" additivity="false"> <AppenderRef ref="Console"/> <AppenderRef ref="RollingFile"/> </Logger> <!--建立一个默认的root的logger--> <root level="info"> <appender-ref ref="RollingFile"/> <appender-ref ref="Error" /> <appender-ref ref="Console"/> </root> </Loggers> </Configuration>