0

调用时 logback 挂起log.error()。我正在使用 SMTPAppender。电子邮件已发送和接收,但进程挂起。这是我的配置:

<configuration>
  <appender name="A3" class="ch.qos.logback.classic.net.SMTPAppender">
      <smtpHost>127.0.0.1</smtpHost>
      <to>qwddwq@asdwzccz</to>
      <from>asdasdqwwwd@ascascaac.org</from>
      <subject>Error</subject>
      <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%d{ISO8601} %-5p [%logger{0}:%line] %m%n</pattern>
      </layout>  
      <cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
        <bufferSize>3</bufferSize>
      </cyclicBufferTracker>
  </appender>

  <logger name="com.jabba" level="DEBUG"/>
  <logger name="org.apache.http" level="INFO"/>
  <logger name="com.eclipse" level="INFO"/>
  <root level="DEBUG">
    <appender-ref ref="A3"/>
  </root>
</configuration>

源代码:

public class LogbackSMTPTester {

    public static void main(final String[] args) throws Exception {
        final Logger log = LoggerFactory.getLogger(LogbackSMTPTester.class);
        log.error("HI MOM! TEST FROM LOGBACKSMTPTESTER!");
    }
}

这是运行时输出:

17:42:35,286 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
17:42:35,286 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
17:42:35,287 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/jabba/conf/test/logback.xml]
17:42:35,466 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
17:42:35,478 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
17:42:35,502 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [A2]
17:42:35,646 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
17:42:35,649 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern jabba.%d{yyyy-MM-dd}.log for the active file
17:42:35,656 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'jabba.%d{yyyy-MM-dd}.log'.
17:42:35,656 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
17:42:35,660 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sat Jul 12 17:42:35 UTC 2014
17:42:35,662 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
17:42:35,705 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[A2] - Active log file name: jabba.2014-07-12.log
17:42:35,705 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[A2] - File property is set to [null]
17:42:35,714 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.net.SMTPAppender]
17:42:35,726 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [A3]
17:42:35,816 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.jabba] to DEBUG
17:42:35,816 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.http] to INFO
17:42:35,816 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.eclipse] to INFO
17:42:35,825 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@35:32 - no applicable action for [configuration], current ElementPath  is [[configuration][configuration]]
17:42:35,825 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
17:42:35,826 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [A2] to Logger[ROOT]
17:42:35,827 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [A3] to Logger[ROOT]
17:42:35,827 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
17:42:35,829 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@77efda65 - Registering current configuration as safe fallback point

它挂在那里。我确实收到了电子邮件。我能找到的唯一参考资料是4 年前来自 Ceki 的,它谈到了更老的 logback 版本中的竞争条件。我在 Linux 上使用logback-classic-1.1.2.jarand logback-core-1.1.2.jar、Java7 和 sendmail 。

帮助!

4

1 回答 1

0

可能您将此文件作为包含文件添加到主 logback.xml 中?在这种情况下,使用代替配置来指示 logback 配置的延续。

<included>
    <appender name="A3" class="ch.qos.logback.classic.net.SMTPAppender">
      <smtpHost>127.0.0.1</smtpHost>
      <to>qwddwq@asdwzccz</to>
      <from>asdasdqwwwd@ascascaac.org</from>
      <subject>Error</subject>
      <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%d{ISO8601} %-5p [%logger{0}:%line] %m%n</pattern>
      </layout>  
      <cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
        <bufferSize>3</bufferSize>
      </cyclicBufferTracker>
    </appender>

    <logger name="com.jabba" level="DEBUG"/>
    <logger name="org.apache.http" level="INFO"/>
    <logger name="com.eclipse" level="INFO"/>
    <root level="DEBUG">
    <appender-ref ref="A3"/>
    </root>
</included>

于 2015-06-17T06:53:06.177 回答