) Log4j: WARN No appenders cocould be found for logger solution, log4jappenders

Source: Internet
Author: User

(Conversion) log4j: WARN No appenders cocould be found for logger solution, log4jappenders

When using Log4j, we always see:

1 log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).2 log4j:WARN Please initialize the log4j system properly.

This problem occurs because the configuration of our log4j. properties file is incomplete, so we will not have this problem if we have configured it.
The incomplete configuration of log4j. properties is as follows:

1 log4j.rootLogger=DEBUG, stdout 2  3 log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 log4j.appender.stdout.layout.ConversionPattern=%c{1} - %m%n 6  7 log4j.logger.java.sql.PreparedStatement=DEBUG 

The complete configuration is as follows:

1 log4j. rootLogger = CONSOLE, FILE 2 log4j.addivity.org. apache = true 3 4 # apply to console 5 log4j. appender. CONSOLE = org. apache. log4j. leleappender 6 log4j. appender. CONSOLE. threshold = INFO 7 log4j. appender. CONSOLE. target = System. out 8 log4j. appender. CONSOLE. encoding = GBK 9 log4j. appender. CONSOLE. layout = org. apache. log4j. patternLayout10 log4j. appender. CONSOLE. layout. conversionPattern = [framework] % d-% c-%-4r [% t] %-5 p % c % x-% m % n11 12 # create a log 13 log4j every day. appender. a1 = org. apache. log4j. dailyRollingFileAppender14 log4j. appender. a1.File = C:/log4j/log15 log4j. appender. a1.Encoding = GBK16 log4j. appender. a1.Threshold = DEBUG17 log4j. appender. a1.DatePattern = '. 'yyyy-MM-dd18 log4j. appender. a1.layout = org. apache. log4j. patternLayout19 log4j. appender. a1.layout. conversionPattern = % d {ABSOLUTE} % 5 p % c {1 }:% L: % m % n20 21 # apply to file 22 log4j. appender. FILE = org. apache. log4j. fileAppender23 log4j. appender. FILE. file = C:/log4j/file. log24 log4j. appender. FILE. append = false25 log4j. appender. FILE. encoding = GBK26 log4j. appender. FILE. layout = org. apache. log4j. patternLayout27 log4j. appender. FILE. layout. conversionPattern = [framework] % d-% c-%-4r [% t] %-5 p % c % x-% m % n28 29 # apply to file rollback 30 log4j. appender. ROLLING_FILE = org. apache. log4j. rollingFileAppender31 log4j. appender. ROLLING_FILE.Threshold = ERROR32 log4j. appender. ROLLING_FILE.File = rolling. log33 log4j. appender. ROLLING_FILE.Append = true34 log4j. appender. lele_file.encoding = GBK35 log4j. appender. ROLLING_FILE.MaxFileSize = 10KB36 log4j. appender. ROLLING_FILE.MaxBackupIndex = 137 log4j. appender. ROLLING_FILE.layout = org. apache. log4j. patternLayout38 log4j. appender. ROLLING_FILE.layout.ConversionPattern = [framework] % d-% c-%-4r [% t] %-5 p % c % x-% m % n39 40 # custom Appender41 log4j. appender. im = net. cybercorlin. util. logger. appender. IMAppender42 log4j. appender. im. host = mail. cybercorlin. net43 log4j. appender. im. username = username44 log4j. appender. im. password = password45 log4j. appender. im. recipient = yyflyons@163.com46 log4j. appender. im. layout = org. apache. log4j. patternLayout47 log4j. appender. im. layout. conversionPattern = [framework] % d-% c-%-4r [% t] %-5 p % c % x-% m % n48 49 # apply to socket50 log4j. appender. SOCKET = org. apache. log4j. rollingFileAppender51 log4j. appender. SOCKET. remoteHost = localhost52 log4j. appender. SOCKET. port = 500153 log4j. appender. SOCKET. locationInfo = true54 # Set up for Log Facter 555 log4j. appender. SOCKET. layout = org. apache. log4j. patternLayout56 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 % n57 # Log Factor 5 Appender58 log4j. appender. LF5_APPENDER = org. apache. log4j. lf5.LF5Appender59 log4j. appender. LF5_APPENDER.MaxNumberOfRecords = 200060 61 # Send Logs to the email 62 log4j. appender. MAIL = org.apache.log4j.net. SMTPAppender63 log4j. appender. MAIL. threshold = FATAL64 log4j. appender. MAIL. bufferSize = 1065 log4j. appender. MAIL. from = yyflyons@163.com66 log4j. appender. MAIL. SMTPHost = www. wusetu. com67 log4j. appender. MAIL. subject = Log4J Message68 log4j. appender. MAIL. to = yyflyons@126.com69 log4j. appender. MAIL. layout = org. apache. log4j. patternLayout70 log4j. appender. MAIL. layout. conversionPattern = [framework] % d-% c-%-4r [% t] %-5 p % c % x-% m % n

Run your program again and you will find that the Log4j warning disappears. However, the previous Log4j console information is also missing. In fact, you only need to set the log4j configured in detail above. rootLogger = CONSOLE, and change FILE to log4j. rootLogger = DEBUG, CONSOLE, FILE, you will find that the CONSOLE information is back.

1 log4j.rootLogger=CONSOLE,FILE2 #log4j.rootLogger=DEBUG,CONSOLE,FILE3 log4j.addivity.org.apache=true

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.