简体   繁体   English

我可以在Web应用程序中使用log4j而不使用log4j.xml或log4j.properties以外的文件吗?

[英]Can I use log4j in a web app with a file other than log4j.xml or log4j.properties?

Is it possible to use something other than the file names log4j.xml or log4j.properties to configure log4j logging in a Java web application? 是否可以使用文件名log4j.xml或log4j.properties以外的其他内容来配置Java Web应用程序中的log4j日志记录?

I want to load a log4j.xml file from a different location on the file path (not in my classpath). 我想从文件路径上的其他位置(而不是在我的类路径中)加载log4j.xml文件。 Is that possible in a web application using say, JBoss or Tomcat? 使用JBoss或Tomcat这样的Web应用程序是否可能?

您可以使用PropertyConfigurator。使用所需的文件调用configure

Use -Dlog4j.configuration=path/to/your/file.xml startup parameter to specify where your configuration file is. 使用-Dlog4j.configuration=path/to/your/file.xml启动参数来指定配置文件的位置。 It's the recommended practice anyway: 无论如何,这是推荐的做法:

The preferred way to specify the default initialization file is through the log4j.configuration system property. 指定默认初始化文件的首选方法是通过log4j.configuration系统属性。

( log4j manual ) log4j手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM