Is there any way to configure log4j loggers dynamically. I want each instance of a class to write to a different file (base on say some property that is unique between instances). I would like to configure everything except the file from XML configuration and then for each instance to set the file.
Is there any way to do this using log4j?
Ok, from your comment, here what i would try.
I imagine you will create your 10 instances at the start of your app.!? anyway.
In your log4j.xml, define 10 appender with name = yourUniqueId (this unique id will be sort of hard coded)
Make these appender write to yourUniqueid.log
Then in your object constructor, instantiate the right Logger with the object unique id.
Something like that:
I think you don’t want to mess around with log4j.xml, then you would have to use the log4j API and create your own appender based on your unique id
Something like this:
This way each instance of YourClass would write to a different log file. all you have to do is think of a way of getting this uniqueId when you call the constructor.
Hope it help.