【发布时间】:2013-12-21 08:53:34
【问题描述】:
我正在使用 log4j 将错误记录到文件中,但是,当我运行我的程序时,我一直收到以下错误,尽管创建了日志文件并将错误记录在文件中,但只有当我退出程序
错误
log4j:ERROR Could not read configuration file [log4j.properties].
java.io.FileNotFoundException: log4j.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:131)
at java.io.FileInputStream.<init>(FileInputStream.java:87)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:372)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:403)
at javafxapplication4.JavaFXApplication4.init(JavaFXApplication4.java:227)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:788)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
at java.lang.Thread.run(Thread.java:724)
log4j:ERROR Ignoring configuration file [log4j.properties].
代码:
PropertyConfigurator.configure("log4j.properties");
...
catch(SQLException e)
{
System.out.println("Error on Database connection");
System.out.print(e.getMessage());
logger.error("Your log message", e);
}
配置文件:
log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=/log/example.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
【问题讨论】:
-
请显示项目层次结构。谢谢
-
在我的编辑中查看层次结构