I added the system environment value PROJECT_HOME=C:\Program Files\Project
Now i'm trying to use the system environment value in log4j.properties but didn't set it
**log4j.properties**
**log4j.appender.LOGFILE.File="${env.PROJECT_HOME}"/project.log**
Could you please tell me how to set system environment variables in log4j.properties?
Using log4j-1.2.7 version
Log4j Properties. The log4j.properties file is a log4j configuration file which stores properties in key-value pairs. The log4j properties file contains the entire runtime configuration used by log4j. This file will contain log4j appenders information, log level information and output file names for file appenders.
The Property Name column contains the name used in properties files and system properties; Environemt Variable for the equivalent environment variable; and Legacy Property Name for the pre-2.10 name. Path to an Log4j 2 configuration file. May also contain a comma separated list of configuration file names. May contain a URL.
To accomplish this, Log4j uses variations of Apache Commons Lang 's StrSubstitutor and StrLookup classes. In a manner similar to Ant or Maven, this allows variables declared as $ {name} to be resolved using properties declared in the configuration itself.
Log4j will inspect the "log4j2.configurationFile" system property and, if set, will attempt to load the configuration using the ConfigurationFactory that matches the file extension. Note that this is not restricted to a location on the local file system and may contain a URL.
This is supported by EnvironmentLookup in log4j - 2. See examples.
Use ${sys:PROJECT_HOME}
instead of ${env.PROJECT_HOME}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With