logback SMTPAppender зависает
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. я использую logback-classic-1.1.2.jar
а также logback-core-1.1.2.jar
, Java7 и sendmail в Linux.
Помогите!
1 ответ
Возможно, вы добавляете этот файл как включаемый файл в мастер 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>