Jorge,

This looks like NDC or MDC would solve the problem.
Have a look at
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/MDC.html

Cheers
--
Steven
 

> -----Original Message-----
> From: Jorge Medina [mailto:[email protected]]
> Sent: Tuesday, 20 January, 2009 18:16
> To: Log4J Users List
> Subject: RE: Orthogonal logging configuration
> 
> For Option (2) I just realized I would have override LogManager, since
> all calls to get a Logger from the Logger class calls methods on
> LogManager.
> 
> Any other ideas are welcome. Thank you.
> 
> -Jorge
> 
> -----Original Message-----
> From: Jorge Medina [mailto:[email protected]]
> Sent: Tuesday, January 20, 2009 6:07 PM
> To: [email protected]
> Subject: Orthogonal logging configuration
> 
> Hi,
>    I have a web services application that can be used by a few clients
> (each client may have several users, but this is not relevant. By
client
> I mean a customer organization, not a client of a client-server
system)
> 
> a)   I would like to have separate log files, one per each client.  Of
> course, there may be sections of code that are executed before I know
> what client is making the request, the log statements on those
sections
> of code would go to the global file.
> 
> b)  I would also like to be able to change the log level per package
per
> client. For example, I want to log at DEBUG level for all requests
> coming from client X but only at INFO level for client Y for a given
> package "com.example.mypackage".
> 
> In other words, package and client would be my orthogonal axis.
> 
> 
>    I was wondering if someone may already have this problem and have a
> solution.
> 
>    Here is what I have been thinking on doing:
> 
> Option 1)
>     Change all Logger.getLogger("x.y.z") for
> Logger.getLogger("clientID.x.y.z") in my code.
>     Advantages:
>         Easy to achieve (a) and (b)
>     Disadvantages:
>         It would only work for my own code, but not for logging
produced
> by third party libraries. (Vgr. Spring, Hibernate, etc). I would
really
> like to log all relevant information into the same log file for a
given
> client. When a request is made, as soon as I know the client, I want
all
> logging of that transaction (my own code, spring, hibernate, other
> libraries) to go to the appropiate appender.
> 
> Option 2)
>      Write my own Logger class, overriding the the Log4j class. The
> Logger.getLogger("x") method will return the logger "clientID.x" if an
> InheritableThreadLocal variable is available with the clientID,
> otherwise it returns logger  "x".
>     Advantages:
>             It will work for my own code and third party code.
>     Disadvantages:
>             Little more complex to implement.
> 
> 
>   I was wondering if anybody have had a similar requirement. Any ideas
> are welcome.
> 
> -Jorge
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to