gpt4 book ai didi

filter - Logback 过滤器不过滤消息

转载 作者:行者123 更新时间:2023-12-01 12:15:40 27 4
gpt4 key购买 nike

我使用下面的过滤器进行了以下设置,希望过滤某些消息。然而,这些消息无论如何都会找到它们进入日志的方式。
事实上,错误日志仅包含过滤器中指定的 WARN 或 ERROR 消息,但其他过滤不起作用。

我不知道发生了什么?

<appender name="ROOT_ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/main-error.log</file>
<filter class="logging.LogbackCustomFilter" />
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${LOG_HOME}/main-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 1GB -->
<maxFileSize>1GB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 7 days' worth of history -->
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date %-5level [%thread] - [%logger] - %msg%n</pattern>
</encoder>
</appender>

<root level="DEBUG">
<appender-ref ref="ROOT_FILE" />
<appender-ref ref="ROOT_ERROR_FILE" />
</root>

日志过滤类:

package logging;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;

public class LogbackCustomFilter extends Filter<ILoggingEvent> {

private static final String closedChannelException = "ClosedChannelException";

private static final String establishedConnectionWasAborted = "An established connection was aborted";

private static final String connectionResetByPeer = "Connection reset by peer";

private static final String brokenPipe = "Broken pipe";

@Override
public FilterReply decide(ILoggingEvent event) {
if (event.getLevel().isGreaterOrEqual(Level.WARN)) {
if (event.getMessage().contains(closedChannelException) ||
event.getMessage().contains(establishedConnectionWasAborted) ||
event.getMessage().contains(connectionResetByPeer) ||
event.getMessage().contains(brokenPipe)) {
return FilterReply.DENY;
} else {
return FilterReply.NEUTRAL;
}
} else {
return FilterReply.DENY;
}
}
}

无论如何,日志中充满了“Connection reset by peer”和“Broken pipe”消息,如下所示:

2018-03-05 21:05:09,933 WARN  [epollEventLoopGroup-2-6] - [io.netty.channel.DefaultChannelPipeline] - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.channel.unix.Errors$NativeIoException: syscall:read(..) failed: Connection reset by peer

或者这个:

2018-03-01 10:33:32,239 ERROR [epollEventLoopGroup-2-10] - [handler.duplex.ExceptionHandler] - channel unhandled exception
io.netty.channel.unix.Errors$NativeIoException: writevAddresses(..) failed: Connection reset by peer
at io.netty.channel.unix.Errors.newIOException(Errors.java:117)
at io.netty.channel.unix.Errors.ioResult(Errors.java:138)
at io.netty.channel.unix.FileDescriptor.writevAddresses(FileDescriptor.java:156)
at io.netty.channel.epoll.AbstractEpollStreamChannel.writeBytesMultiple(AbstractEpollStreamChannel.java:278)
at io.netty.channel.epoll.AbstractEpollStreamChannel.doWriteMultiple(AbstractEpollStreamChannel.java:505)
at io.netty.channel.epoll.AbstractEpollStreamChannel.doWrite(AbstractEpollStreamChannel.java:442)
at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0(AbstractChannel.java:934)
at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.epollOutReady(AbstractEpollChannel.java:555)
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:394)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:304)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
at java.lang.Thread.run(Thread.java:748)

最佳答案

在示例消息中,event.getMessage() 将仅返回记录的第一行(例如 “An exceptionCaught() event was fired...”“ channel 未处理的异常”)。

要深入了解以下异常的消息,请尝试 event.getThrowableProxy().getMessage()

自然地,通常也不会有相关的异常 - 您还需要允许 event.getThrowableProxy() 为 null。

关于filter - Logback 过滤器不过滤消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48482006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com