Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
nvtd4000
Contributor III
Contributor III

How to use environment variable in log4j.xml to dynamically set up the log file path

I am using log4j 2 in Talend studio (licensed with Bigdata platform v7.3.1) to log information to log files. I hardcode the path of log file (in property basePath) to my local path: "/Users/aaaa/log". So far so good. I can see the information in log files. Now, what i want is :

Instead of hardcode the value of path, I set up an environment variable in OS: $LOG_PATH = /Users/aaaa/log and I want to use this env variable in log4j.xml

I have tried with either of below but none of them works. I don't see log file after I run the job in Talend Studio.

  • <Property name ="basePath">${env:LOG_PATH}</Property>
  • <Property name="basePath">${sys:LOG_PATH}</Property>

Could you please help me to do that. (And If it doesn't work when running job in Talend Studio, will it work when i deploy the job to Remote Engine ?)

Here is my log4j.xml:

0695b00000Hum09AAB.png

2 Replies
Anonymous
Not applicable

For the log4j custom configuration in studio, it may require some additional investigation and also custom coding for which we would suggest to involve CSE or PS team, and we will need a support ticket to take this further.

However, just to let you know that starting Remote Engine v2.11.0, there is possibility to setup custom log4j appenders as explained in the documentation here:

 

https://help.talend.com/r/en-US/Cloud/remote-engine-user-guide-linux/custom-logging-config-in-re

gjeremy1617088143

Hi , you could check this article :

https://community.talend.com/s/question/0D55b00006J1xjvCAB/use-a-variable-for-filename-in-log4j

it's one way to hardcode the filename path at the launch of runtime.

so if you can get the Env variable via java it could be donne like that.

Maybe it can help you

Send me love and kudos