1、创建一个单独的Appender
<RollingFile name="TESTLOG" fileName="${LOG_PATH}/test_error.log" filePattern="${LOG_PATH}/test_error-%d{yyyyMMdd}-%i.log.gz"> <PatternLayout pattern="%d{yyyy/MM/dd HH:mm:ss.SSS} %t [%p] %c{1} (%F:%L) %msg%n" /> <Filters> <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/> </Filters> <Policies> <TimeBasedTriggeringPolicy interval="1" modulate="true"/> <SizeBasedTriggeringPolicy size="256MB"/> </Policies> <DefaultRolloverStrategy> <Delete basePath="${LOG_PATH}" maxDepth="2"> <IfFileName glob="test_error-*.log.gz" /> <IfLastModified age="3d" /> </Delete> </DefaultRolloverStrategy> </RollingFile>
2、添加对应的Logger
<Loggers> <Root level="INFO"> <Appender-ref ref="Console"/> <Appender-ref ref="FILEINFO"/> <Appender-ref ref="FILEERROR"/> </Root> <Logger name="com.xxx.dao.mapper" level="debug" additivity="false"> <Appender-ref ref="FILEINFO"/> </Logger> <!--日志再单独一份输出到指定文件下, 如想在正常的日志中再打印一次配置additivity="ture" --> <Logger name="test_log" level="info" additivity="false"> <Appender-ref ref="TESTLOG"/> </Logger> </Loggers>
3、代码中
private final static Logger logger = LoggerFactory.getLogger("test_log");
@Override
public void printLog() {
//打印到TESTLOG对应Appender的目录文件
logger.info("-------test-----------");
}
这样日志就单独打印到test_error.log了,
来源:oschina
链接:https://my.oschina.net/u/3783256/blog/3120113