Many log4cxx users raise this question: how do I use log4cxx in a multi-process environment? Currently log4cxx gives a "don't" answer or a "use a different log file per process" answer, which are correct, but sometimes not very easy to implement. We had the same problem in our product, we spawn a process with the same name many times and that architecture isn't going to change.
I think I have implemented a large part of a solution. Issue 1: how can one name a log file differently per-process without any code? I added two formatting pattern converters: ProcessIdPatternConverter and ProcessNamePatternConverter. %p translates to the process ID and %n to the process name. This is very nice because it's zero code to enable multi-process logging and works for the RollingFileAppender as well. So my log files look like this: SomeExecutable.1234.log. Issue 2: with the above scheme there's a proliferation of log files (one per process x rolling file appender maxindex). How can I clean them up? I added a purge option. When the logger initializes (activateOptions) it will take the filename pattern, format it, but instead of using a ProcessIdPatternConverter it will use some star pattern converter producing SomeExecutable.*.log for example. Then I just delete files that match this pattern. This cleans up old log files. Repeat this with the rolling filenames, except %i also gets replaced with *. What do you guys think? I have this for Windows (GetProcessID, GetModuleFilename, FindFirstFile, DeleteFile etc.), but I don't know how to make it portable. I need some help with that. Cheers dB. www.dblock.org / www.foodcandy.com
