英文:
Overwrite Dlog4j.configuration Java argument
问题
我正在使用 Weblogic 服务器,并在服务器启动时使用 -Dlog4j.configuration 参数设置了一个用于部署应用程序的常见路径。然而,对于一个新的应用程序,我想要设置一个不同的路径并忽略这个参数。因此,我添加了以下内容到 web.xml 文件中:
<context-param>
<param-name>log4jConfig</param-name>
<param-value>META-INF/log4j.properties</param-value>
</context-param>
但这并没有覆盖我的参数。有没有一种方法可以覆盖它?
英文:
I am using a Weblogic server and have -Dlog4j.configuration argument set in server start up with a common path for the deployed applications. However, for a new application I want to set a different path and ignore this argument. As such I added:
<context-param>
<param-name>log4jConfig</param-name>
<param-value>META-INF/log4j.properties</param-value>
</context-param>
to web.xml file, which did not overwritte my argument. Is there a way to overwrite it?
答案1
得分: 0
请注意,**log4j.properties(或log4j.xml)**文件需要包含在Weblogic类路径中;假设您已将其放置在文件夹“C:\Weblogic\user_projects\domains\base_domain\config”中,那么您需要将此目录添加到服务器的Classpath文本项中。
以下的log4j.properties定义了一个RollingFileAppender,它将日志写入您的域根目录:(C:\Weblogic\user_projects\domains\base_domain)
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=mylog.log
log4j.appender.rollingFile.MaxFileSize=2MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
log4j.rootLogger = INFO, rollingFile
最后的努力,因为WebLogic服务器在域中不加载任何Log4j库,将是将log4j包含在DOMAIN_HOME/lib
子目录中。在那里放置Log4j实现(log4j-X.X.X
)和Weblogic的Log4j库(wllog4j.jar
),这些是服务器分发的一部分。
英文:
Remember that the log4j.properties (or log4j.xml) file needs to be included into Weblogic classpath; thus, supposing that you have placed it into the folder “C:\Weblogic\user_projects\domains\base_domain\config”, then you need adding this directory into the server Classpath text item.
The following log4j.properties defines a RollingFileAppender which will write logs to your domain root directory:(C:\Weblogic\user_projects\domains\base_domain)
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=mylog.log
log4j.appender.rollingFile.MaxFileSize=2MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
log4j.rootLogger = INFO, rollingFile
Last effort, since WebLogic Server does not load any Log4j library in your domain, will be to include log4j in the DOMAIN_HOME/lib
subdirectory. Place there a Log4j implementation (log4j-X.X.X
) and Weblogic’s Log4j libraries (wllog4j.jar
) which are part of the server distribution.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论