最近在项目有个需求就是不同的日志类型打印到不同的文件中去
logback.xml文件:
<appender name="test" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_PATH}/test/test.log</File>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
<marker>TEST</marker>
</evaluator>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/test/test.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>5</maxHistory>
<MaxFileSize>500MB</MaxFileSize>
</rollingPolicy>
<encoder>
<pattern>${logging_pattern}</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
这个配置项一定要放到logback.xml的最后
<root>
<level value="INFO"/>
<appender-ref ref="test"/>`
</root>
使用:就会打印到我们定义好的test.log的文件里面去了
public static final Marker test= MarkerFactory.getMarker("TEST");
log.info(test,"测试自定义日志打印");