1

I have a file transfer application that has a requirement to write specific events to a specific log file, while all events go to the commong log file. For example:

File comes in from source A, events get written to file.log
File comes in from source B, events get written to file.log and B_file.log
File comes in from source C, events get written to file.log
...

I was thinking of creating a "BLog" appender in my log4j config, and in my application group all of my source B files/directories into one configuration and assigning "BLog" to it, and in the code check everytime we transfer files if the configuration has an appender, if so, get it and call doAppend.

However, if I add the appender to the log4j config, won't that make it receive all events? Can I create the appender without assigning it to root in the config but still get it programatically? If so, does that mean everytime I want to send an event to B_file.log, I have to get the appender, add it to root, call doAppend, then remove the appender?

Is there a cleaner way to do this?

Thanks in advance!

Cthulhujr
  • 359
  • 3
  • 12

1 Answers1

0

I think your question could be resolved by applying the solution to this question:

log4j: Log output of a specific class to a specific appender

and adding calls in your custom appender to also write to the primary appender.

Hope this helps

Community
  • 1
  • 1
StormeHawke
  • 5,987
  • 5
  • 45
  • 73