开发者

logback socketappender not working from webapp

开发者 https://www.devze.com 2023-04-08 15:03 出处:网络
I use logback in my maven project and send logs using socketappender. However, the socketappender works only when i run a junit test but when I run my project from tomcat (open a web page) only consol

I use logback in my maven project and send logs using socketappender. However, the socketappender works only when i run a junit test but when I run my project from tomcat (open a web page) only console appender works. I used lilith and the sample server in the from the logabck jar. Here is my logback.xml which is the same as logback-test.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="RootSocketAppender" class="ch.qos.logback.classic.net.SocketAppender">
<remoteHost>127.0.0.1</remoteHost>
<port>4560</port>
<reconnectionDelay>30000</reconnectionDelay>
<includeCallerData>false</includeCallerData>
</appender>
    <root level="warn">
        <appender-ref ref="console" />
        <appender-ref ref="RootSocketAppender" />
    </root>

</configuration>

I get this messages from tomcat console when I deploy the app:

10:29:45,794 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
    10:29:45,794 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/D:/programmation/workspace/eclipse/.metadata/.plu开发者_如何转开发gins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp/WEB-INF/classes/logback-test.xml]
    10:29:45,794 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs multiple times on the classpath.
    10:29:45,794 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs at [file:/D:/programmation/workspace/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp/WEB-INF/classes/logback-test.xml]
    10:29:45,794 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs at [jar:file:/D:/programmation/workspace/eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp/WEB-INF/lib/backoffice.jar!/logback-test.xml]
    10:29:45,856 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
    10:29:45,856 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
    10:29:45,856 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [console]
    10:29:45,872 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
    10:29:45,903 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [foo] to INFO
    10:29:45,903 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.core] to INFO
    10:29:45,903 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.beans] to INFO
    10:29:45,903 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.context] to INFO
    10:29:45,903 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.test] to TRACE
    10:29:45,903 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.web] to INFO
    10:29:45,903 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN
    10:29:45,903 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [console] to Logger[ROOT]

thanks


Logback can't found the RootSocketAppender in your logback-test.xml. Make sure that it contains this appender and it's attached to the root logger.

Note that there is a logback-test.xml in the WEB-INF/classes/ directory and an other one in the WEB-INF/lib/backoffice.jar. Maybe you should have only one in your application.

0

精彩评论

暂无评论...
验证码 换一张
取 消