I have a requirement where i need to change the log location dynamically depending on the parameter received from command line. Like i will be receiving $LogLocation parameter from another input and now i have to generate my logs in location "$LogLocation/test/log" I am using log4j2.
Asked
Active
Viewed 292 times
0
-
1Possible duplicate of [override log4j configuration programmatically: file location for FileAppender](http://stackoverflow.com/questions/14242521/override-log4j-configuration-programmatically-file-location-for-fileappender) – Sully Nov 11 '16 at 11:10
-
@Hitham S. AlQadheeb, The one you pointed above is for log4j. I am facing issue with log4j2. – Rogger296 Nov 11 '16 at 13:24
-
Check http://stackoverflow.com/questions/26668938/how-to-configure-logger-programmatically-in-log4j2-02 – Sully Nov 12 '16 at 08:49
-
I solved the issue, but stack overflow has banned me from answering. – Rogger296 Nov 16 '16 at 12:59
-
If you can't post an answer yet, then just describe the solution in a comment. It might help someone. – Sully Nov 16 '16 at 17:23
-
1Solution : I used the ThreadContext like as shown below. ThreadContext.put("LogLocation ", commandLineArgs.get("LogLocation ")); Then loading the log configuration from log4j2.xml. Above parameter is extracted in log4j2.xml as shown below
$${ctx:LogLocation}/test/log – Rogger296 Dec 06 '16 at 07:40