eclipse(indigo) java project项目:log4j的配置文件放哪儿?

对岸 发布于 2013/11/23 14:22
阅读 906
收藏 0

1.我看的是孙鑫的书上的例子,那上面说要把配置文件(hello.lcf)放到和.class文件同一个目录下;

2.因为书上只有在控制台java Hello hello.lcf这样执行程序;没有说在eclipse里配置文件放哪儿?————我试了一下也把hello.lcf放到bin目录,或者src目录,或者2个目录都放了那个配置文件,但都是找不到配置文件!

错误信息:

log4j:ERROR Could not read configuration file [hello.lcf].
java.io.FileNotFoundException: hello.lcf (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:297)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:315)
at Hello.main(Hello.java:13)
log4j:ERROR Ignoring configuration file [hello.lcf].
log4j:WARN No appenders could be found for logger (Hello).
log4j:WARN Please initialize the log4j system properly.


------------------

Hello.java
import org.apache.log4j.Logger;
//import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;

public class Hello
{

    static Logger logger = Logger.getLogger(Hello.class);

    public static void main(String args[])
    {
        //BasicConfigurator.configure();
        PropertyConfigurator.configure("hello.lcf");

        logger.debug("Hello world.");
        logger.info("Welcome you.");
    }
}



Hello.lcf

#设置根记录器的日志级别为DEBUG,Appender为A1
log4j.rootLogger=DEBUG,A1


#设置A1为ConsoleAppender
log4j.appender.A1=org.apache.log4j.ConsoleAppender


#A1使用PatternLayout
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%r [%t] %p %c %x - %m%n




加载中
0
华兹格
华兹格
src目录下,刷新下
对岸
对岸
PropertyConfigurator.configure("hello.lcf");
对岸
对岸
谢谢,已解决!——是路径的问题,应该是src/hello.jcf
返回顶部
顶部