简体   繁体   English

如何从属性 object 配置 log4j2?

[英]How to configure log4j2 from Properties object?

Can log4j2 be initialized from Properties object (no properties file)?可以从属性 object(无属性文件)初始化 log4j2 吗? This was supported in old log4j 1.2.x (see code below), but I didn't find how to implement this with new log4j2.这在旧的 log4j 1.2.x 中得到支持(见下面的代码),但我没有找到如何用新的 log4j2 实现它。

Properties props = new Properties();
// ...set some properties
PropertyConfigurator.configure(props);

Did you try looking on the Apache Log4J 2 Documentation website?您是否尝试查看Apache Log4J 2 文档网站?

There's the GitHub apache / logging-log4j2 where you have a section detailing the Usage with code snippets.在 GitHub apache / logging-log4j2中有一个部分详细说明了代码片段的用法

Please, keep in mind the security vulnerabilities issues discovered in Log4j 2. Recommended you upgrade to Log4j 2.3.1 (for Java 6), 2.12.3 (for Java 7), or 2.17.0 (for Java 8 and later). Please, keep in mind the security vulnerabilities issues discovered in Log4j 2. Recommended you upgrade to Log4j 2.3.1 (for Java 6), 2.12.3 (for Java 7), or 2.17.0 (for Java 8 and later). As recommended also in Apache Log4j 2 website.正如Apache Log4j 2网站中所推荐的那样。 There are also answers on StackOverflow like this one log4j2 -version 2.5 - How to Configure log4j2 using a java.util.properties object StackOverflow上也有答案,例如log4j2 -version 2.5 - How to Configure log4j2 using a java.util.properties object

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

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