自定义lockback拦截配置
程序员文章站
2022-03-05 08:16:59
...
方法一:需要配置拦截字符
1.在 <evaluator>子标签下, message.contains("response :"),contains里面就是配置需要拦截的字符串。如果当行里面有xxxx,就拦截下来
<!-- Configure the monthly calculator log -->
<appender name="JSONOUT" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression>return message.contains("response :");</expression>
</evaluator>
<OnMatch>NEUTRAL</OnMatch>
<OnMismatch>DENY</OnMismatch>
</filter>
<file>H:/Java/workspace_one/OCR_Server/logs/ocr_server_json_result.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Daily rollover -->
<fileNamePattern>H:/Java/workspace_one/OCR_Server/logs/ocr_server_json_result.log.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- Keep 180 days' worth of history -->
<maxHistory>180</maxHistory>
</rollingPolicy>
<encoder>
<pattern>
%d{HH:mm:ss.SSS} %-5level [%thread] %logger - %msg%n
</pattern>
</encoder>
</appender>
2.最后还不要忘记添加
<appender-ref ref="JSONOUT" />
3.不输出一些框架信息
把不想输出的包路径写进去
<logger name="org.springframework" level="info" />
不输出info级别,只输出debug级别的:
<!-- Root Logger -->
<root>
<priority value="debug" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</root>
4.依赖包:
compile 'org.slf4j:slf4j-api:1.7.12'
compile 'org.slf4j:jcl-over-slf4j:1.7.12'
compile 'ch.qos.logback:logback-classic:1.1.3'
compile 'org.codehaus.janino:janino:3.0.0'
compile 'org.codehaus.janino:commons-compiler:3.0.0'
Ref:
http://logback.qos.ch/manual/filters.html
方法二:分文件
1.
<appender name="REGULAR_EXP" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>{path}/regular_exp_result.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level-%msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Daily rollover -->
<fileNamePattern>{path}/regular_exp_result.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- Keep 180 days' worth of history -->
<maxHistory>180</maxHistory>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>50KB</maxFileSize>
</triggeringPolicy>
</appender>
2.
<logger name="REGULAR_EXP" level="DEBUG">
<appender-ref ref="REGULAR_EXP" />
</logger>
3.new logger 使用
private static final Logger regExLogger = LoggerFactory.getLogger("REGULAR_EXP");
上一篇: Swap Nodes in Pairs
下一篇: Swap Nodes in Pairs
推荐阅读
-
wamp安装后自定义配置的方法_PHP
-
SpringBoot实现自定义配置文件提示的方法
-
MyBatis自定义SQL拦截器示例详解
-
DotNetCore跨平台~在appsettings.json里自定义配置项
-
Bigcommerce:config.php的配置有关问题:无法写入自定义的新的配置信息
-
Java笔记-CXF增加拦截器与自定义拦截器
-
简单的实现登录拦截及统一异常处理(自定义异常)
-
Spring配置shiro时自定义Realm中属性无法使用注解注入的解决办法
-
手把手带你自定义配置Angular CLI下的Webpack和loader处理
-
Spring Boot自定义配置属性源(PropertySource)