Can anyone please guide me as to how I can configure log4j to log to a specific file that I specify at run-time.The name and path of the log file are generated at run-time and the application must log to that particular file.
Generally file appender entries in the log4j.properties file points to the log file that will be used by the application.However in this case I would like to read the log file path from the command line and log to that particular file.
How can I achieve this ?
Adapted from the log4j documentation:
Can be also done by this properties define in log4j.properties file
You can also do this from the log4j.properties file. Using the sample file below I have added the system property ${logfile.name}:
The log file name can then be set two different ways:
In the java program directly by setting a system property (BEFORE you make any calls to log4j).
System.setProperty("logfile.name","some path/logfile name string");
Working and same has been tested