log4j:WARN找不到记录器的appender。 Log4j 1.2.17罐子

时间:2014-10-28 06:50:24

标签: java logging log4j

我收到此错误

log4j:WARN No appenders could be found for logger (com.company.Main).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

这是我的主要

package com.company;

import org.apache.log4j.Logger;

public class Main {
    final static Logger logger = Logger.getLogger(Main.class);
    public static void main(String[] args) {

        if(logger.isDebugEnabled()){
            logger.debug("This is debug");
        }

        //logs an error message with parameter
        logger.error("This is error");
    }
}

虽然这是我的log.properties文件

# Root logger option
log4j.rootLogger = DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout                             = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target                      = System.out
log4j.appender.stdout.layout                      = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern    = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Redirect log messages to a log file, support file rolling.
log4j.appender.file                               = org.apache.log4j.RollingFileAppender
log4j.appender.file.File                          = C:\\log4j-application.log
log4j.appender.file.MaxFileSize                   = 5MB
log4j.appender.file.MaxBackupIndex                = 10
log4j.appender.file.layout                        = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern      = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

这是我的文件结构。

我正处于Log4J的学习阶段,并试图实现一个虚拟项目来深入理解它。

1 个答案:

答案 0 :(得分:1)

您必须将ressources目录添加到类路径中。之后它应该有效。