logback socketappender无法从webapp工作

时间:2011-09-26 08:18:21

标签: java-ee logging maven logback appender

我在maven项目中使用logback并使用socketappender发送日志。但是,socketappender仅在我运行junit测试时工作,但是当我从tomcat(打开网页)运行我的项目时,只有控制台appender工作。 我在logabck jar中使用了lilith和sample server。 这是我的logback.xml,它与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>

我在部署应用程序时从tomcat控制台收到此消息:

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/.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 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]

感谢

1 个答案:

答案 0 :(得分:1)

在您的RootSocketAppender中无法找到logback-test.xml。确保它包含此appender并且它已附加到root记录器。

请注意,logback-test.xml目录中有一个WEB-INF/classes/,另一个目录中有WEB-INF/lib/backoffice.jar {{1}}。也许你的申请中应该只有一个。