我正在開發一個移動應用程序,並使用log4j來顯示信息。我想使用log4j在控制檯上顯示正確執行的信息,但是當我嘗試添加SMTPAppender以在發生錯誤時發送電子郵件時遇到問題。它不顯示錯誤,但是當我添加SMTPAppender啓動它時,tomcat無法正確啓動。log4j Console和SMTPAppender:如何使用多個appender
我使用Apache Tomcat 7.0.23
這是我log4j.properties文件
log4j.rootCategory=TRACE, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [application] %-5p %m%n
log4j.rootCategory=ERROR, mail
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
#defines how often emails are send
log4j.appender.mail.BufferSize=1
log4j.appender.mail.SMTPHost=smtp.gmail.com
log4j.appender.mail.SMTPUsername=******* #not the username im using
log4j.appender.mail.SMTPPassword=******* #not the password im using
[email protected]
[email protected]
log4j.appender.mail.Subject="Application.log error occurred"
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d{ISO8601} [application] %-5p %m%n
這是我的控制檯
Found binding in [jar:file:/C:/Documents%20and%20Settings/noconnor/.m2/repository/org/slf4j/slf4j-simple/1.6.1/slf4j-simple-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Documents%20and%20Settings/noconnor/.m2/repository/org/slf4j/slf4j-log4j12/1.6.2/slf4j-log4j12-1.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
這是添加第二個正確的方法appender還是我在某個地方犯了一個錯誤?
順便說一句,也看到這個如何解決它在使用屬性語法:http://stackoverflow.com/a/728351/47190(注意'閾值'參數)。 –