When we use log4j, we always show:
Java code Log4j:warn No Appenders could is found for logger (org.apache.ibatis.logging.LogFactory). Log4j:warn Initialize the log4j system properly.
This problem is because our Log4j.properties file configuration is not complete enough, so we configured it so that it won't happen again.
The log4j.properties is not fully configured as follows:
Java code log4j.rootlogger=debug, stdout Log4j.appender.stdout=org.apache.log4j.consoleappender log4j.appender.st Dout.layout=org.apache.log4j.patternlayout Log4j.appender.stdout.layout.conversionpattern=%c{1}-%m%n Log4j.log Ger.java.sql.preparedstatement=debug
The complete configuration is as follows:
Java code log4j.rootlogger=console,file log4j.addivity.org.apache=true # applications for consoles 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 #应用于文件 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 #自定义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 #应用于socket log4j.appender.socket= org.apache.log4j.rollingfileappender log4j.appender.socket.remotehost=localhost   log4j.appender.socket.port=5001 log4j.appender.socket.locationinfo=true # Set up for log facter 5 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 # log factor 5 appender log4j.appender.lf5_appender=org.apache.log4j.lf5.lf5appender Log4j.appender.LF5_APPENDER. maxnumberofrecords=2000 # send logs to mail 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=log4j message 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'll notice that log4j's warning disappears. But found that the previous LOG4J console information is not, in fact, as long as the above detailed configuration of the log4j.rootlogger=console,file changed to Log4j.rootlogger=debug,console,file, you will find that The console information is back.
Java code log4j.rootlogger=console,file #log4j. Rootlogger=debug,console,file log4j.addivity.org.apache=true
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.