我无法让Logback ServerSocketReceiver工作。我在运行Logback自己的完整示例https://logback.qos.ch/manual/receivers.html时遇到了完全相同的问题。
简化的logback.xml
:
<configuration debug="true">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%date]-%msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
<receiver class="ch.qos.logback.classic.net.server.ServerSocketReceiver">
<port>3331</port>
</receiver>
</configuration>
套接字服务器甚至从未启动:
ERROR in ch.qos.logback.core.model.processor.DefaultProcessor@76b10754 - Can't handle model of type class ch.qos.logback.classic.model.ReceiverModel with tag: receiver at line 11
使用此设置完成输出:
20:22:22,951 |-INFO in ch.qos.logback.classic.LoggerContext[default] - This is logback-classic version 1.4.11
20:22:22,953 |-INFO in ch.qos.logback.classic.util.ContextInitializer@305fd85d - No custom configurators were discovered as a service.
20:22:22,953 |-INFO in ch.qos.logback.classic.util.ContextInitializer@305fd85d - Trying to configure with ch.qos.logback.classic.joran.SerializedModelConfigurator
20:22:22,953 |-INFO in ch.qos.logback.classic.util.ContextInitializer@305fd85d - Constructed configurator of type class ch.qos.logback.classic.joran.SerializedModelConfigurator
20:22:22,971 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.scmo]
20:22:22,971 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.scmo]
20:22:22,978 |-INFO in ch.qos.logback.classic.util.ContextInitializer@305fd85d - ch.qos.logback.classic.joran.SerializedModelConfigurator.configure() call lasted 19 milliseconds. ExecutionStatus=INVOKE_NEXT_IF_ANY
20:22:22,978 |-INFO in ch.qos.logback.classic.util.ContextInitializer@305fd85d - Trying to configure with ch.qos.logback.classic.util.DefaultJoranConfigurator
20:22:22,978 |-INFO in ch.qos.logback.classic.util.ContextInitializer@305fd85d - Constructed configurator of type class ch.qos.logback.classic.util.DefaultJoranConfigurator
20:22:22,979 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
20:22:22,981 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/x/Projects/agent-tcp-logging/server/target/classes/logback.xml]
20:22:23,067 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - Processing appender named [CONSOLE]
20:22:23,067 |-INFO in ch.qos.logback.core.model.processor.AppenderModelHandler - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
20:22:23,071 |-INFO in ch.qos.logback.core.model.processor.ImplicitModelHandler - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
20:22:23,080 |-INFO in ch.qos.logback.classic.model.processor.RootLoggerModelHandler - Setting level of ROOT logger to DEBUG
20:22:23,081 |-INFO in ch.qos.logback.core.model.processor.AppenderRefModelHandler - Attaching appender named [CONSOLE] to Logger[ROOT]
20:22:23,084 |-ERROR in ch.qos.logback.core.model.processor.DefaultProcessor@76b10754 - Can't handle model of type class ch.qos.logback.classic.model.ReceiverModel with tag: receiver at line 11
20:22:23,085 |-WARN in ch.qos.logback.core.model.processor.ImplicitModelHandler - Ignoring unknown property [port] in [ch.qos.logback.classic.LoggerContext]
20:22:23,085 |-ERROR in ch.qos.logback.core.model.processor.DefaultProcessor@76b10754 - Can't handle model of type class ch.qos.logback.classic.model.ReceiverModel with tag: receiver at line 11
20:22:23,085 |-INFO in ch.qos.logback.core.model.processor.DefaultProcessor@76b10754 - End of configuration.
20:22:23,086 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@71a794e5 - Registering current configuration as safe fallback point
20:22:23,086 |-INFO in ch.qos.logback.classic.util.ContextInitializer@305fd85d - ch.qos.logback.classic.util.DefaultJoranConfigurator.configure() call lasted 108 milliseconds. ExecutionStatus=DO_NOT_INVOKE_NEXT_IF_ANY
任何帮助将非常感谢。
Java 8、11、17我尝试了多个版本的Logback,但我更喜欢1.3.x,因为我在生产中使用Java 8。(最终我会切换到SSLSocketReceiver/appender)
附加器似乎工作。我做了一个“假”服务器,它连接到没有问题。
当Logback初始化时,我得到ERROR in ch.qos.logback.core.model.processor.DefaultProcessor@76b10754 - Can't handle model of type class ch.qos.logback.classic.model.ReceiverModel with tag: receiver at line 11
我希望Logback启动一个套接字服务器,该服务器将在端口3331上启动侦听。
1条答案
按热度按时间oug3syen1#
如果你使用的是logback 1.3,那么你需要注意你链接的页面上代码示例的Canonical(1.3)标签:
解决方案
接收方的xml必须与上述内容类似。
注意:class是
ServerSocketReceiver
而不是ch.qos.logback.classic.net.server.ServerSocketReceiver
。