如何从非src文件夹强制log4j加载xml配置?

Den*_* S. 9 java xml log4j

是否可以从源根目录中加载不同目录的log4j.xml以及如何加载?(以编程方式?)意味着它在FS中的某个地方而不仅仅是在类路径中.

Mar*_*ark 20

使用DOMConfigurator,您可以指定用于配置log4j的XML文件.

DOMConfigurator.configure("/path/to/log4j.xml");
Run Code Online (Sandbox Code Playgroud)

对于log4j.properties,您可以使用PropertyConfigurator执行相同的操作.

PropertyConfigurator.configure("/path/to/log4j.properties");
Run Code Online (Sandbox Code Playgroud)