log4j:WARN No appenders could be found for logger [How to Solve]

When we are using Log4j, it always appears that

Java code

log4j:WARNNoappenderscouldbefoundforlogger(org.apache.ibatis.logging.LogFactory).

log4j:WARNPleaseinitializethelog4jsystemproperly.

This problem is because our log4j.properties file configuration is not complete enough, so we give it a full configuration will no longer have this problem.

The incomplete configuration of log4j.properties is as follows.

 

Java code

log4j.rootLogger=DEBUG,stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%c{1}-%m%n

log4j.logger.java.sql.PreparedStatement=DEBUG

The complete configuration is as follows.

 

Java code

log4j.rootLogger=CONSOLE,FILE

log4j.addivity.org.apache=true

#Application to Console

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender

log4j.appender.CONSOLE.Threshold=INFO

log4j.appender.CONSOLE.Target=System.out

log4j.appender.CONSOLE.Encoding=GBK

log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout

log4j.appender.CONSOLE.layout.ConversionPattern=[framework]%d-%c-%-4r[%t]%-5p%c%x-%m%n

#New log daily

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender

log4j.appender.A1.File=C:/log4j/log

log4j.appender.A1.Encoding=GBK

log4j.appender.A1.Threshold=DEBUG

log4j.appender.A1.DatePattern=’.’yyyy-MM-dd

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE}%5p%c{1}:%L:%m%n

#Apply to file

log4j.appender.FILE=org.apache.log4j.FileAppender

log4j.appender.FILE.File=C:/log4j/file.log

log4j.appender.FILE.Append=false

log4j.appender.FILE.Encoding=GBK

log4j.appender.FILE.layout=org.apache.log4j.PatternLayout

log4j.appender.FILE.layout.ConversionPattern=[framework]%d-%c-%-4r[%t]%-5p%c%x-%m%n

#Apply to file rollback

log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender

log4j.appender.ROLLING_FILE.Threshold=ERROR

log4j.appender.ROLLING_FILE.File=rolling.log

log4j.appender.ROLLING_FILE.Append=true

log4j.appender.CONSOLE_FILE.Encoding=GBK

log4j.appender.ROLLING_FILE.MaxFileSize=10KB

log4j.appender.ROLLING_FILE.MaxBackupIndex=1

log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout

log4j.appender.ROLLING_FILE.layout.ConversionPattern=[framework]%d-%c-%-4r[%t]%-5p%c%x-%m%n

#Custom Appender

log4j.appender.im=net.cybercorlin.util.logger.appender.IMAppender

log4j.appender.im.host=mail.cybercorlin.net

log4j.appender.im.username=username

log4j.appender.im.password=password

log4j.appender.im.recipient=yyflyons@163 .com

log4j.appender.im.layout=org.apache.log4j.PatternLayout

log4j.appender.im.layout.ConversionPattern=[framework]%d-%c-%-4r[%t]%-5p%c%x-%m%n

#Applications to sockets

log4j.appender.SOCKET=org.apache.log4j.RollingFileAppender

log4j.appender.SOCKET.RemoteHost=localhost

log4j.appender.SOCKET.Port=5001

log4j.appender.SOCKET.LocationInfo=true

#SetupforLogFacter5

log4j.appender.SOCKET.layout=org.apache.log4j.PatternLayout

log4j.appender.SOCET.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD]%n%c[CATEGORY]%n%m[MESSAGE]%n%n

#LogFactor5Appender

log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender

log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000

#Send log to email

log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender

log4j.appender.MAIL.Threshold=FATAL

log4j.appender.MAIL.BufferSize=10

log4j.appender.MAIL.From=yyflyons@163 .com

log4j.appender.MAIL.SMTPHost=www.wusetu.com

log4j.appender.MAIL.Subject=Log4JMessage

log4j.appender.MAIL.To=yyflyons@126 .com

log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout

log4j.appender.MAIL.layout.ConversionPattern=[framework]%d-%c-%-4r[%t]%-5p%c%x-%m%n

 

Run your program again and you will find that the Log4j warnings are gone. However, you find that the previous Log4j console message is also gone. In fact, just change the log4j.rootLogger=CONSOLE,FILE configured in detail above to log4j.rootLogger=DEBUG,CONSOLE,FILE and you will find that the console message is back.

 

Java Code

log4j.rootLogger=CONSOLE,FILE

#log4j.rootLogger=DEBUG,CONSOLE,FILE

log4j.addivity.org.apache=true

Similar Posts: