Unknown Source in Log4j
Log4j日志记录机制中的Unknown Source问题解析
(本文将不对log4j的语法及使用情况作说明,详细内容参考apache官方网站的logging项目)
在使用log4j的系统中,使用ant将程序打包之后,运行过程中记录的日志中代码行数(Line Number)并没有打印出来,而是显示Unknown Source消息,具体过程如下:
在NetBeans中建立工程NBLog4jTest工程,结构如下:
ProjectName
src
log4j.properties
Main.java
lib
log4j-1.2.13.jar
JDK 1.5(default)
默认类文件内容如下:
/*
* Main.java
*
* Created on 27 September 2007, 21:19
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package javaapplication1;
import org.apache.log4j.Logger;
/**
*
* @author Administrator
*/
public class Main {
private static final Logger logger=Logger.getLogger(Main.class);
/** Creates a new instance of Main */
public Main() {
if(logger.isDebugEnabled()){
logger.debug("in Constructor of Main");
}
}
public void print(String message){
if(logger.isDebugEnabled()){
logger.debug("in print method of Main");
logger.debug("printing:"+message+"......");
}
System.out.println(message);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main main=new Main();
main.print("HelloWorld!");
}
}
其中将log4j-1.2.13.jar文件放在src目录内,并将其添加到classpath中。
log4j.properties文件内容如下:
# Sample ResourceBundle properties file
log4j.rootLogger=DEBUG,system,trace
#s
推荐文章 |
