简体   繁体   English

如何禁用log4j servlet初始化?

[英]How can i disable log4j servlet initialization?

The scenario is the following: I have an existing web app, which initializes log4j through a servlet: 场景如下:我有一个现有的Web应用程序,该应用程序通过servlet初始化log4j:

<servlet>
    <servlet-name>log4j-init</servlet-name>
    <servlet-class>com.app.Log4jInitServlet</servlet-class>
    <init-param>
        <param-name>log4j-init-file</param-name>
        <param-value>WEB-INF/classes/log4j.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

No i want to override this initialization through an external file passed in log4j.configuration JVM ardument: -Dlog4j.configuration=file:/usr/local/log4j.xml 不,我想通过在log4j.configuration JVM中传递的外部文件覆盖此初始化:-Dlog4j.configuration = file:/usr/local/log4j.xml

When i start the application server I can see that the external file is being picked up first but then the internal file through the initialization servlet will override the changes. 当我启动应用程序服务器时,我可以看到首先提取了外部文件,但是随后通过初始化servlet的内部文件将覆盖所做的更改。

My question is how can i disable the servlet initialization through some king of JVM param configuration(preferable), without having to modify the application web.xml and/or initialization servlet? 我的问题是如何通过某些JVM参数配置(首选)禁用servlet初始化,而不必修改应用程序web.xml和/或初始化servlet? Or is there a way to specify the order in which the initialization should be done ? 还是有一种方法可以指定初始化的顺序?

Thanks 谢谢

The log4j init servlet is not part of core log4j. log4j初始化servlet不属于核心log4j。 I'll assume that you are using the init servlet suggested in tutorial present here https://logging.apache.org/log4j/1.2/manual.html In such a case whatever file you specify in the servlet init file parameter is going to be used for init. 我假设您正在使用本教程中建议的初始化servlet,该教程在此处提供https://logging.apache.org/log4j/1.2/manual.html在这种情况下,您在servlet初始化文件参数中指定的任何文件都将用于初始化。

I don't think you can accomplish this without modifying either the web.xml or the init servlet 我认为如果不修改web.xml或init servlet,就无法完成此任务

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

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