Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use system environment variables in log4j.properties?

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

like image 528
deepaksharma Avatar asked Mar 10 '14 09:03

deepaksharma


People also ask

What are the properties of Log4j?

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.

What is PROPERTY NAME column in Log4j?

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.

How do I resolve variables in Log4j?

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.

How does log4j2 load configuration files?

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.


1 Answers

This is supported by EnvironmentLookup in log4j - 2. See examples.

Use ${sys:PROJECT_HOME} instead of ${env.PROJECT_HOME}

like image 190
Leos Literak Avatar answered Oct 20 '22 16:10

Leos Literak