How to set log4j property file?

前端 未结 3 1125
孤街浪徒
孤街浪徒 2021-02-13 03:25

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.

He

3条回答
  •  -上瘾入骨i
    2021-02-13 03:51

    You can set VM argument : -Dlog4j.configuration='path_to_log4j.xml'

    or programatically :

    String logFilePath = new File();
    if (logFilePath == null || "".equalsIgnoreCase(logFilePath)) {
        URL file = this.getClass().getResource(DEFAULT_CONF);
        DOMConfigurator.configure(file);
    } else {
        DOMConfigurator.configure();   
    }
    

提交回复
热议问题