1

I'm looking for a way to define transitive log message routing. Let's say we have an application called poly with these packages:

com.mycompany.server-common
com.mycompany.communication
com.mycompany.webservice

server-common is used by both of the 2 others. All 3 use org.hibernate as well.

Now, I like to have 1 logfile for the webservice component with all messages from com.mycompany.webservice and with those messages from com.mycompany.server-common and org.hibernate that were initiated by the webservice. And then, another coresponding file for the communication package.

My application is a war file running in tomcat, where all components run in 1 context (it comes in 1 war file). I already defined the multiple log files, but they naturally only log that what i defined statically, there is no transitive inclusion.

I would be very interested in ideas how I could achieve the desired behaviour. I already thought about using the MDC for that, but I'm not sure if that's a good idea. Another idea was to separate the contexts, but I think in the current project state this will be hard and it does not offer the flexibility I hope for.

Any hints or discussions are appreciated.

mkraemerx
  • 1,713
  • 2
  • 17
  • 21
  • 1
    An NDC or MDC is the simplest approach, what's your concern with either? – Dave Newton Oct 18 '11 at 14:17
  • @DaveNewton just didn't use them yet, so I wanted some more experience-based opinions – mkraemerx Oct 18 '11 at 14:19
  • They're handy for stuff like this, although I've often done some customization on the output format to be more "normalized", like putting a user entry first, or a component first, etc. depending on needs. – Dave Newton Oct 18 '11 at 14:27

1 Answers1

2

If you set an MDC key when webservice starts serving a request and clear the MDC key at the end of the request, SiftingAppender will do what you are asking. Shout on the logback-user mailing list if you run into difficulties.

Ceki
  • 26,753
  • 7
  • 62
  • 71