我正在尝试将错误日志邮寄到 gmail。但是 logback 不发送任何邮件,我也没有收到任何错误,即使我将用户名更改为随机无效邮件。我认为它不会尝试发送邮件。
我在主函数中记录了 500 封邮件,但它只记录到文件和控制台附加程序中。
for(int i=0;i<501;i++){
logger.error("mail test");
}
请参阅 logback.xml、pom.xml 和控制台输出。
问候,
**logback.xml**
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<smtpHost>smtp.gmail.com</smtpHost>
<smtpPort>465</smtpPort>
<SSL>true</SSL>
<username>myMail@gmail.com</username>
<password>aaaaa</password>
<to> myMail@gmail.com</to>
<from> myMail@gmail.com</from>
<subject>TESTING: %logger{20} - %m</subject>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%date %-5level %logger{35} - %message%n</pattern>
</layout>
</appender>
.....
<root level="TRACE">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="EMAIL" />
</root>
**pom.xml**
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.3</version>
</dependency>
Connected to the target VM, address: '127.0.0.1:51152', transport: 'socket'
23:25:31,588 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
23:25:31,588 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
23:25:31,588 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/D:/projects/TmfCorbaTester/target/classes/logback.xml]
23:25:31,686 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
23:25:31,702 |-INFO in ch.qos.logback.core.joran.action.StatusListenerAction - Added status listener of type [ch.qos.logback.core.status.OnConsoleStatusListener]
23:25:31,736 |-INFO in ch.qos.logback.classic.joran.action.LoggerContextListenerAction - Adding LoggerContextListener of type [ch.qos.logback.classic.jul.LevelChangePropagator] to the object stack
23:25:31,737 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@8a548b - Propagating DEBUG level on Logger[ROOT] onto the JUL framework
23:25:31,742 |-INFO in ch.qos.logback.classic.joran.action.LoggerContextListenerAction - Starting LoggerContextListener
23:25:31,746 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.net.SMTPAppender]
23:25:31,768 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [EMAIL]
23:25:31,871 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
23:25:31,875 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
23:25:31,925 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use zip compression
23:25:31,927 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern D:/projects/TmfCorbaTester/TmfCorbaTester-%d-%i.log for the active file
23:25:31,931 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@1d87b85 - The date pattern is 'yyyy-MM-dd' from file name pattern 'D:/projects/TmfCorbaTester/TmfCorbaTester-%d-%i.log.zip'.
23:25:31,931 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@1d87b85 - Roll-over at midnight.
23:25:31,932 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@1d87b85 - Setting initial period to Sat Apr 07 23:19:35 EEST 2012
23:25:31,936 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Cleaning on start up
23:25:31,936 |-INFO in ch.qos.logback.core.rolling.helper.SizeAndTimeBasedArchiveRemover@f8395f - first clean up after appender initialization
23:25:31,936 |-INFO in ch.qos.logback.core.rolling.helper.SizeAndTimeBasedArchiveRemover@f8395f - periodsElapsed = 64
23:25:31,979 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: D:\projects\TmfCorbaTester/TmfCorbaTester.log
23:25:31,980 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [D:\projects\TmfCorbaTester/TmfCorbaTester.log]
23:25:31,981 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
23:25:31,983 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
23:25:31,990 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
23:25:31,990 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUTJACORB]
23:25:31,991 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [jacorb] to DEBUG
23:25:31,991 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@8a548b - Propagating DEBUG level on Logger[jacorb] onto the JUL framework
23:25:31,994 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [jacorb] to false
23:25:31,994 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[jacorb]
23:25:31,996 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUTJACORB] to Logger[jacorb]
23:25:31,996 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to TRACE
23:25:31,996 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@8a548b - Propagating TRACE level on Logger[ROOT] onto the JUL framework
23:25:31,996 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT]
23:25:32,001 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
23:25:32,001 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [EMAIL] to Logger[ROOT]
23:25:32,001 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
23:25:32,003 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@14b6bed - Registering current configuration as safe fallback point
mail test
**23:25:32,017 |-INFO in ch.qos.logback.classic.net.SMTPAppender[EMAIL] - SMTPAppender [EMAIL] is tracking [1] buffers**
mail test
mail test
mail test
mail test
..
..
.