[英]How to separate logging by severity to different files using springboot and logback
Im trying to send different logs to different files using logback. 我试图使用回传将不同的日志发送到不同的文件。
I have 2 appenders configured (Console, RollingFile) and i want all 我配置了2个附加程序(控制台,RollingFile),我想要全部
logback-spring.xml logback-spring.xml
<root level="error">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<logger name="com.mypkg" level="trace" additivity="true">
<appender-ref ref="RollingFile" />
</logger>
<logger name="com.mypkg" level="info" additivity="true">
<appender-ref ref="Console" />
</logger>
The result of the above configuration has 2 problems : 以上配置的结果有两个问题:
any idea what im doing wrong ? 我知道我在做什么错吗? is there any default spring logback file the is somehow merged with this config in runtime (changing the additivity to false fix the duplication issue, but still no TRACE messages) ? 是否有任何默认的spring logback文件,它在运行时以某种方式与此配置合并(将加性更改为false来解决复制问题,但仍然没有TRACE消息)?
Thanks . 谢谢 。
You can try logback filters. 您可以尝试登录过滤器。 There is a filter called LevelFilter. 有一个名为LevelFilter的过滤器。 The option to accept and ignore log level types is also available here. 此处还提供接受和忽略日志级别类型的选项。
Example : 范例:
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>
%-4relative [%thread] %-5level %logger{30} - %msg%n
</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
More information is in the below logback documentation. 有关更多信息,请参见下面的注销文档。
https://logback.qos.ch/manual/filters.html#levelFilter https://logback.qos.ch/manual/filters.html#levelFilter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.