简体   繁体   中英

Using log4j2 property substitution with properties defined in another file

I'm working on a project using log4j2, and have some values in my log4j2.properties which are configurable. This project will also include a configuration file for other components. Ideally, I'd like to keep all my configuration in one place so I'd like to be able to set those configurable values for log4j in that same file, so that I don't have two different places where config values are subject to change (including environment variables, for example).

The ways I've found around this are less than ideal, like having other parts of my project read the values from the main config file and put them into system variables to be picked up by log4j, since I'd like to avoid writing code to set up log4j outside of its own properties file.

Is there any way to directly reference values defined in other properties files in log4j2.properties? If not, it this possible in one of the configuration file formats log4j2 can use, like XML or JSON?

To clarify, I'm aware of the various ways lookup methods available in log4j2 but since I'm storing these values in a different file none of them are as "clean" as being able to reference that file directly.

The Log4j2 configuration has a properties section, and if all keys are known in advance, you can get each of the values from another lookup , like the system properties lookup or a custom lookup.

It may be a good idea to suggest getting Log4j2 configuration properties from an external properties file as a new feature request on the Log4j2 JIRA issue tracker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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