在 RESTEasy 中禁用服务器发送事件错误的日志记录
Disable logging for server-sent-events errors in RESTEasy
我目前正在使用 Wildfly 中的 RESTEasy 处理服务器发送的事件。到目前为止,一切正常,除了有时 SSE 实现无法识别监听事件 is/are 的客户端已经关闭(也是 SseEventSource
客户端上的 close() 方法-side 被称为)。在程序逻辑方面这根本不是问题。
但不幸的是 org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl
class 用于发送事件 - 除了将异常报告回 org.jboss.resteasy.plugins.providers.sse.SseBroadcasterImpl
- 不仅报告异常,还记录日志它使用 org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages
的 failedToWriteSseEvent(String, Throwable)
方法(后来 class 基于 JBoss 日志记录)。所以我时不时地收到一条错误级别的不必要的日志消息,告诉我连接已被客户端关闭。除了我从 SseBroadcaster
.
获得的 onClose 事件外,它还会在日志中获得该条目
配置 JBoss 日志记录似乎是不可能的,因为日志名称是 org.jboss.resteasy.resteasy_jaxrs.i18n
,它也用于记录其他错误(意味着只需在部署的 log4j.xml 中配置记录器不工作/也关闭其他错误)。
2021-06-22 12:59:27 [ERROR] [org.jboss.resteasy.resteasy_jaxrs.i18n:272] - RESTEASY002030: Failed to write event org.jboss.resteasy.plugins.providers.sse.OutboundSseEventImpl@fd79b33
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.writev0(Native Method)
at sun.nio.ch.SocketDispatcher.writev(Unknown Source)
at sun.nio.ch.IOUtil.write(Unknown Source)
at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
at org.xnio.nio.NioSocketConduit.write(NioSocketConduit.java:162)
at io.undertow.server.protocol.http.HttpResponseConduit.write(HttpResponseConduit.java:647)
at io.undertow.conduits.ChunkedStreamSinkConduit.doWrite(ChunkedStreamSinkConduit.java:166)
at io.undertow.conduits.ChunkedStreamSinkConduit.write(ChunkedStreamSinkConduit.java:128)
at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
at io.undertow.channels.DetachableStreamSinkChannel.write(DetachableStreamSinkChannel.java:240)
at io.undertow.server.HttpServerExchange$WriteDispatchChannel.write(HttpServerExchange.java:2103)
at io.undertow.servlet.spec.ServletOutputStreamImpl.writeBufferBlocking(ServletOutputStreamImpl.java:574)
at io.undertow.servlet.spec.ServletOutputStreamImpl.flushInternal(ServletOutputStreamImpl.java:489)
at io.undertow.servlet.spec.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:476)
at io.undertow.servlet.spec.HttpServletResponseImpl.flushBuffer(HttpServletResponseImpl.java:468)
at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper.flushBuffer(HttpServletResponseWrapper.java:124)
at org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl.writeEvent(SseEventOutputImpl.java:264)
at org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl.send(SseEventOutputImpl.java:199)
at org.jboss.resteasy.plugins.providers.sse.SseBroadcasterImpl.lambda$null(SseBroadcasterImpl.java:150)
at java.lang.Iterable.forEach(Unknown Source)
at org.jboss.resteasy.plugins.providers.sse.SseBroadcasterImpl.lambda$broadcast(SseBroadcasterImpl.java:146)
at java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source)
at java.util.concurrent.CompletableFuture$AsyncRun.exec(Unknown Source)
at java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source)
at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
有没有办法在 RESTEasy 中控制日志记录并禁用 failedToWriteSseEvent(String, Throwable)
的日志记录?就像引入/注入自己的 LogMessages
实现一样(但据我所知,该接口用作代理,所以...)?
您可能会击中 RESTEASY-1986。不过,您可以使用日志过滤器过滤掉这些。在 CLI 中类似于:
/subsystem=logging/logger=org.jboss.resteasy.resteasy_jaxrs.i18n:add(filter-spec=not(match(".*RESTEASY002030.*")), level=INFO)
我目前正在使用 Wildfly 中的 RESTEasy 处理服务器发送的事件。到目前为止,一切正常,除了有时 SSE 实现无法识别监听事件 is/are 的客户端已经关闭(也是 SseEventSource
客户端上的 close() 方法-side 被称为)。在程序逻辑方面这根本不是问题。
但不幸的是 org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl
class 用于发送事件 - 除了将异常报告回 org.jboss.resteasy.plugins.providers.sse.SseBroadcasterImpl
- 不仅报告异常,还记录日志它使用 org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages
的 failedToWriteSseEvent(String, Throwable)
方法(后来 class 基于 JBoss 日志记录)。所以我时不时地收到一条错误级别的不必要的日志消息,告诉我连接已被客户端关闭。除了我从 SseBroadcaster
.
配置 JBoss 日志记录似乎是不可能的,因为日志名称是 org.jboss.resteasy.resteasy_jaxrs.i18n
,它也用于记录其他错误(意味着只需在部署的 log4j.xml 中配置记录器不工作/也关闭其他错误)。
2021-06-22 12:59:27 [ERROR] [org.jboss.resteasy.resteasy_jaxrs.i18n:272] - RESTEASY002030: Failed to write event org.jboss.resteasy.plugins.providers.sse.OutboundSseEventImpl@fd79b33
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.writev0(Native Method)
at sun.nio.ch.SocketDispatcher.writev(Unknown Source)
at sun.nio.ch.IOUtil.write(Unknown Source)
at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
at org.xnio.nio.NioSocketConduit.write(NioSocketConduit.java:162)
at io.undertow.server.protocol.http.HttpResponseConduit.write(HttpResponseConduit.java:647)
at io.undertow.conduits.ChunkedStreamSinkConduit.doWrite(ChunkedStreamSinkConduit.java:166)
at io.undertow.conduits.ChunkedStreamSinkConduit.write(ChunkedStreamSinkConduit.java:128)
at org.xnio.conduits.ConduitStreamSinkChannel.write(ConduitStreamSinkChannel.java:150)
at io.undertow.channels.DetachableStreamSinkChannel.write(DetachableStreamSinkChannel.java:240)
at io.undertow.server.HttpServerExchange$WriteDispatchChannel.write(HttpServerExchange.java:2103)
at io.undertow.servlet.spec.ServletOutputStreamImpl.writeBufferBlocking(ServletOutputStreamImpl.java:574)
at io.undertow.servlet.spec.ServletOutputStreamImpl.flushInternal(ServletOutputStreamImpl.java:489)
at io.undertow.servlet.spec.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:476)
at io.undertow.servlet.spec.HttpServletResponseImpl.flushBuffer(HttpServletResponseImpl.java:468)
at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:221)
at org.jboss.resteasy.plugins.server.servlet.HttpServletResponseWrapper.flushBuffer(HttpServletResponseWrapper.java:124)
at org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl.writeEvent(SseEventOutputImpl.java:264)
at org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl.send(SseEventOutputImpl.java:199)
at org.jboss.resteasy.plugins.providers.sse.SseBroadcasterImpl.lambda$null(SseBroadcasterImpl.java:150)
at java.lang.Iterable.forEach(Unknown Source)
at org.jboss.resteasy.plugins.providers.sse.SseBroadcasterImpl.lambda$broadcast(SseBroadcasterImpl.java:146)
at java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source)
at java.util.concurrent.CompletableFuture$AsyncRun.exec(Unknown Source)
at java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source)
at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
有没有办法在 RESTEasy 中控制日志记录并禁用 failedToWriteSseEvent(String, Throwable)
的日志记录?就像引入/注入自己的 LogMessages
实现一样(但据我所知,该接口用作代理,所以...)?
您可能会击中 RESTEASY-1986。不过,您可以使用日志过滤器过滤掉这些。在 CLI 中类似于:
/subsystem=logging/logger=org.jboss.resteasy.resteasy_jaxrs.i18n:add(filter-spec=not(match(".*RESTEASY002030.*")), level=INFO)