如何设置log4j属性文件? [英] How to set log4j property file?

查看:92
本文介绍了如何设置log4j属性文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用log4j的Eclipse Java项目.我无法设置要通过文件路径访问的log4j配置文件.我必须在jar中导出并运行该项目.

I have an Eclipse Java Project which uses log4j. I can't set the log4j configuration file to be accessed by file path. I have to export and run the project in a jar.

这是我的尝试方式:

public class Wita {
  static Logger logger;
  public static void main(String[] args) {
    System.setProperty("log4j.configuration", new File("").getCanonicalPath()+File.separatorChar+"resources"+File.separatorChar+"log4j.xml" );
    // System.out.println( System.getProperty("log4j.configuration") );
    logger = Logger.getLogger(Wita.class.getName());
  }
}

系统输出将打印出 C:\ Users \ roncsak \ eclipse_workspace \ WITA \ resources \ log4j.xml . WITA 是项目的基本文件夹.但是,使用 -Dlog4j.debug 参数运行项目时,也会返回以下内容:

System out prints the C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml which is good. WITA is the base folder of the project. But running the project with -Dlog4j.debug argument the following returns also:


log4j: Trying to find [C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@18e3e60.
log4j: Trying to find [C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml] using sun.misc.Launcher$AppClassLoader@18e3e60 class loader.
log4j: Trying to find [C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml] using ClassLoader.getSystemResource().
log4j: Could not find resource: [C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml].

我想随着时间的推移更改log4j.xml,而不构建另一个jar文件.我该怎么办?

I would like to change the log4j.xml over time, without building another jar file. How can I do that?

推荐答案

来自

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆