简体   繁体   English

库的Log4j2配置

[英]Log4j2 configuration of library

I have the following application structure.我有以下应用程序结构。

1- Outer app which is executed directly via console. 1- 直接通过控制台执行的外部应用程序。 It's log4j configuration is provided via log4j2.configurationFile property.它的 log4j 配置是通过 log4j2.configurationFile 属性提供的。

2- Inner apps which is executed through ProcessBuilder. 2- 通过 ProcessBuilder 执行的内部应用程序。 They are also configured the same way as outer app.它们的配置方式也与外部应用程序相同。

The problem is outer applications configuration file overrides inner ones'.问题是外部应用程序配置文件覆盖了内部应用程序的配置文件。 So, every application takes the outer app's log4j2 configuration file.因此,每个应用程序都使用外部应用程序的 log4j2 配置文件。 In inner applications, using LoggerContext, it works but there are restrictions preventing me to change inner applications.在内部应用程序中,使用 LoggerContext,它可以工作,但有一些限制阻止我更改内部应用程序。 How can I resolve this issue?我该如何解决这个问题?

Set up a different environment property for the sub-process via the ProcessBuilder before you launch:在启动之前通过ProcessBuilder为子流程设置不同的环境属性:

ProcessBuilder pb = // whatever you use now

pb.environment().put("log4j2.configurationFile", otherLog4JPropFile);
 
Process p = pb.start();

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

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