logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jorge Medina" <jmed...@e-dialog.com>
Subject RE: Orthogonal logging configuration
Date Wed, 21 Jan 2009 18:49:15 GMT

Thanks to all for their suggestions. Very useful !!
I still would like to have the same functionality from DailyRollingFileAppender (so that the
logs per client also get rolled periodically.)
I will take a look at the code of the MDC, SiftingAppender and MultiFileAppender and may combine
them to satisfy my needs.

The beauty of open source! Thanks a lot!


-----Original Message-----
From: Ceki Gulcu [mailto:ceki@qos.ch] 
Sent: Wednesday, January 21, 2009 6:01 AM
To: Jorge Medina
Subject: Re: Orthogonal logging configuration

Hello Jorge,

I think logback's SiftingAppender is exactly what are looking for.
See http://logback.qos.ch/manual/appenders.html#SiftingAppender


Jorge Medina wrote:
> 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

Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.

To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org

View raw message