Hello list,

I'm currently working on an application which does some testing based on a
test specification. For each new run of the test specification a new
directory is created and the whole data belonging to the test spec is stored
there. This includes the log files.

At the beginning of each thread (before I start running the test spec) I do
the following:
   Logger log = Logger.getLogger(testDir + "." + MyClass.class);
   Appender appender = new FIleAppender(..., testDir + "test.log");
   log.addAppender(appender);
   log.setAdditivity(false);

and at the end of the thread:
   log.removeAppender(appender);


The idea is to separate logging from the main log of the application and to
flush the log file buffers and close the log file at the end. What bothers
me is that the Logger instances starting from 'testDir + "."' are left. Is
there a way to remove them from log4j? Something like
Logger.removeLogger(testDir + ".*");. I don't think that the app will be
running out of memory if I leave them each time, but still it's pretty ugly
because the loggers would never be used again.

Also is there a better way to create separate logs for each thread? I know
about NDC and MDC but I really need separate log files. It would also be
nice to be able to use the PropertyConfigurator for the separate threads,
that way more can be done than the simple hard coded FileAppender.

best regards,
Aleksandar

Reply via email to