网站首页 新闻首页 网页设计图形动画软件编程网站开发办公软件操作系统数据库网络技术认证考试范文资料黑客攻防 书籍教程 进入论坛

Unknown Source in Log4j

http://www.diybl.com/ 2008-3-27  网络 点击:  [ 评论 ]
文章搜索:    【点击打包该文章】

 
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

如果图片或页面不能正常显示请点击这里 站内搜索:   

文章评论

请您留言