简体   繁体   English

如何在有条件的情况下在运行时在log4j配置文件之间切换

[英]How to switch between log4j configuration files at runtime with a condition

I have two different log4j.properties files. 我有两个不同的log4j.properties文件。 One is for production and the other one is for sandbox. 一种用于生产,另一种用于沙箱。 Normally, application uses log4j.properties. 通常,应用程序使用log4j.properties。 But for sandbox version (by using a condition) I want that application should use a properties file which is created by me and named as sandbox-log4j.properties. 但是对于沙箱版本(使用条件),我希望该应用程序应使用由我创建并命名为sandbox-log4j.properties的属性文件。 Only difference between them is a log tracking line is added to sandbox version. 它们之间的唯一区别是将日志跟踪行添加到沙箱版本。

How could I make a switch between two files by using a conditin in a java file? 如何通过在Java文件中使用conditin在两个文件之间进行切换?

I found the answer. 我找到了答案。 @Michael's suggestion on JVM helped me to handle the problem. @Michael对JVM的建议帮助我解决了这个问题。 I use Elastic Beanstalk and its JVM options field on Configuration provided to separate log4j.properties files. 我使用提供的Configuration上的Elastic Beanstalk及其JVM选项字段来分隔log4j.properties文件。 Setting JVM options to -Dlog4j.configuration=sandbox-log4j.properties is enough for solution. 将JVM选项设置为-Dlog4j.configuration=sandbox-log4j.properties解决。

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

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