可以在同一个 Tomcat Web 应用程序中使用多个 log4j.properties 文件吗?
我正在为现成的 Java Web 应用程序编写自定义扩展。该应用程序使用 log4j 进行日志记录,我想专门为我的扩展添加一个新的记录器和附加程序。问题在于应用程序管理 log4j.properties 文件,该文件是根据管理屏幕 UI 中的选择动态生成的。由于这是一个“现成的”应用程序,我无法修改源代码。所以,如果我添加自己的记录器 &附加到文件中,只要管理员更改 UI 中的日志首选项,它就会被覆盖。
是否可以让 log4j 从 2 个文件中获取其配置?例如,我想要如下所示的内容:
applog.properties #(Dynamically generated from admin UI)
mylog.properties #(My static properties)
在这种情况下,log4j 会以某种方式组合两个文件中的条目以获得完整的配置。
这可能吗?或者还有其他解决方法吗?
I'm writing a custom extension to an off-the-shelf Java web application. The application uses log4j for logging and I'd like to add a new logger and appender specifically for my extension. The problem is that the application manages the log4j.properties file which is dynamically generated based on selections in an admin screen UI. Since this is an "off-the-shelf" application, I can't modify the source code. So, if I add my own logger & appender(s) to the file, it gets overwritten anytime an admin changes logging preferences in the UI.
Is it possible to get log4j to get it's configuration from 2 files? For example, I'd want something like the following:
applog.properties #(Dynamically generated from admin UI)
mylog.properties #(My static properties)
In this scenario, log4j would somehow combine the entries from both files for the complete configuration.
Is this possible? or are there other workarounds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从未找到一种方法来“合并”多个 log4j.properties 文件,但我确实找到了一个可行的解决方案。 log4j 配置可以在运行时以编程方式进行操作,类似于下面的代码片段。这有效地将我的自定义 log4j 设置合并到 log4j.properties 文件定义的配置中,在我的情况下,我无法编辑该配置。
I never did find a way to "merge" multiple log4j.properties file, but I did find a workable solution. log4j configuration can be manipulated programatically at runtime similar to the code snippet below. This effectively merged my custom log4j settings into the configuration defined by the log4j.properties file, which in my case I couldn't edit.