2
我試圖設置我的記錄器實例來在應用程序生成錯誤日誌時發送郵件。我想過爲此使用Gmail。我的logger.xml如下:Logback SMTPAppender不能與gmail配置一起工作
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/path-to-application/application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>/path-to-application/application-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 250MB -->
<maxFileSize>250MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date - %thread [%level] - %message%n%xException%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date - %thread [%level] - %message%n%xException%n</pattern>
</encoder>
</appender>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<smtpHost>smtp.gmail.com</smtpHost>
<smtpPort>465</smtpPort>
<ssl>true</ssl>
<username>[email protected]</username>
<password>abc's password</password>
<asynchronousSending>false</asynchronousSending>
<to>[email protected]@gmail.com</to>
<!--<to>ANOTHER_EMAIL_DESTINATION</to> <!– additional destinations are possible –>-->
<from>[email protected]</from>
<subject>TESTING: %logger{20} - %m</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date %-5level %logger{35} - %message%n</pattern>
</layout>
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<!-- send just one log entry per email -->
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
</appender>
<logger name="play" level="WARN"/>
<logger name="application" level="INFO"/>
<root level="ERROR">
<!-- <appender-ref ref="STDOUT" /> -->
<appender-ref ref="EMAIL"/>
</root>
</configuration>
我在我的SBT文件中添加了javax.mail和激活作爲依賴關係。滾動文件appender和控制檯appender工作正常,但SMTP appender似乎不適用於這些設置。錯誤日誌正在我的滾動文件中記錄,但沒有作爲郵件發送。沒有例外情況被記錄,以便我可以進一步調查。
這些規範有問題嗎?或者問題可能出自gmail smtp服務器端?
我能解決這個問題前一段時間與你所提到的什麼。不幸的是,完全忘記在這裏更新它。謝謝 。 – t6nand