Reputation: 2047
I'm using log4j2, and have my configuration in log4j2.xml (in classpath so it s automatically configured)
In this particular case, I want to create separate log files per process.
I have a framework with multiple packages and multiple classes. They all have statements like:
Logger logger = LogManager.getLogger(getClass());
Lets say I now have three processes A, B and C. How should I configure log4j to get three output files A.log, B.log and C.log and include the logging calls made in the framework classes?
I also want to be able to log individual packages/classes to other log appenders if I need to debug etc, so I would prefer to keep the getClass() argument mentioned above.
All ideas are welcome!
Upvotes: 1
Views: 1117
Reputation: 42010
You can add the desired name at the time of creating the process, adding an argument to the Java virtual machine. e.g.:
java -Dcustom.log.name=/tmp/logs/A.log ... ...
So, you can use it:
<File name="Application" fileName="${custom.log.name}">
See more in Apache Log4j 2 User's Guide [PDF].
Upvotes: 1
Reputation: 36754
Give every process its own configuration file. Specify different paths in these configurations.
You can specify the full path of the configuration file with this system property:
-Dlog4j.configurationFile=path/to/log4j2.xml
Upvotes: 0