14

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

deepaksharma
  • 281
  • 3
  • 6
  • 12
  • 1
    What is your log4j version? Only log4j 2 supports this? See docs: http://logging.apache.org/log4j/2.x/manual/lookups.html – Jayan Mar 10 '14 at 10:45
  • Any reason for staying with 1.x version? Version 2 shall be faster and more reliable. – Leos Literak Mar 10 '14 at 12:25
  • 1
    For log4j 1.2.x, see the accepted answer for this question: https://stackoverflow.com/questions/13066042/how-to-give-environmental-variable-path-for-file-appender-in-configuration-file – aff Mar 01 '18 at 05:00

1 Answers1

15

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

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

Jayan
  • 18,003
  • 15
  • 89
  • 143
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
  • 1
    Could you be more specific? What does it mean "not able to generate"? Is it created or not? Is there some exception? What is your project - plain java / web app? – Leos Literak Mar 10 '14 at 09:44
  • @ Leos Literak : could you point to relevant documentation on log4j? I did not know log4j tries to read environment variables. – Jayan Mar 10 '14 at 10:41
  • @Jayan See http://logging.apache.org/log4j/2.x/manual/configuration.html, search for sys:. I have troubles with their doc to get all information / syntax. You need to seek it there. – Leos Literak Mar 10 '14 at 11:11
  • OP did not clarify his log4j version. I edited your answer anyway... :) – Jayan Mar 10 '14 at 11:24
  • 2
    I've searched for more than an hour for this answer! Good to know the differences between the versions... – Bartis Áron Sep 07 '15 at 16:55