logback SMTPAppender挂起

时间:2014-07-12 17:49:49

标签: logging logback smtpappender

调用log.error()时,

logback挂起。我正在使用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 years ago from Ceki,它讨论了一个更老的回溯版本中的竞争条件。我在linux上使用logback-classic-1.1.2.jarlogback-core-1.1.2.jar,Java7和sendmail。

帮助!

1 个答案:

答案 0 :(得分:0)

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

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

相关问题