logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Womack <mwom...@bevocal.com>
Subject RE: User-level filtering
Date Wed, 08 Jan 2003 18:39:23 GMT
This is the basic idea if you are going to use MDC.  You might want to
create your own custom filter that assumes the user key in the MDC but takes
a list of user id's that you want to have logged.  You could possibly to
some optimzations for performance.  You can use the MDCMatchFilter class as
a basis for this.

Also, if you are doing this in a web application, you may want to look at
the current cvs in the package org.apache.log4j.servlet.  There is a
CookieMDCFilter.java class which can be configured to take cookie values
from requests and stuff them into the MDC.  So, if your user id were stored
in a cookie, you could have it set up by this filter (using a Servlet 2.3
compatible container) at the start of each web request.  Then your MDC
filtering would work as outlined.

hth,
-Mark

> -----Original Message-----
> From: Shorn Tolley [mailto:shorntolley@yahoo.co.uk]
> Sent: Tuesday, January 07, 2003 9:31 PM
> To: Log4J Users List
> Subject: RE: User-level filtering
> 
> 
> Here's the basic idea:
> 
> At some central point in your app (before most other
> logging takes place) you find out the username of the
> user initiating the request.
> 
> Stick this user name in the MDC with some key, say
> "user.name".
> 
> Then attach an MDCMatchFilter to your appender and
> configure it to filter out log messages except those
> with given usernames.
> 
> This means that only log messages for you're specified
> usernames will be logged.
> 
> In order to do the thing you were talking about though
> (most users get ERROR logging but specific users get
> DEBUG logging) you might need to experiment with
> chaining the MDCMatch filter with a priority filter,
> or possibly extend the MDCMatchFilter class to do
> exactly what you want.  It shouldn't be hard.
> 
> I think that's what you want.
> 
> You can find MDCMatchFilter and NDCMatchFilter in the
> CVS repository under package
> "org.apache.log4j.filters".
> 
> You'll also need to get the MatchFilterBase class.
> 
> Make sure your using the DOMConfigurator for adding
> filters.
> 
> Cheers,
> Shorn.
> 
> 
>  --- Lutz Michael <michael.h.lutz@siemens.com> wrote:
> > 
> > 
> > Maybe I'm not aware of the full power of MDC.
> > 
> > My understanding of MDC is that at a thread level,
> > custom key/value pairs
> > are stored in a stack and their output controlled by
> > the configuration file.
> > The effect is that these values don't need to be set
> > on each log call,
> > rather Log4j remembers them and intelligently
> > outputs them based on pattern
> > layout settings.  The values are remembered on a per
> > thread basis.
> > 
> > What I'm interested in, rather, is setting the
> > logging level (e.g. DEBUG,
> > ERROR, etc.) for a specific user.  Specifically, I'd
> > like to leave the
> > entire application set to ERROR (or WARN) and set
> > the class instances used
> > by a **specific user** to DEBUG.  Essentially, in
> > addition to setting the
> > logging level by the logging hierarchy, I'd like to
> > add "user" to the
> > criteria.
> > 
> > In a large scale WEB environment, I'm thinking this
> > capability is important,
> > especially classes with the same fully qualified
> > class name used across an
> > application's business functions.
> > 
> > 
> > 
> 
> http://movies.yahoo.com.au - Yahoo! Movies
> - What's on at your local cinema?
> 
> --
> To unsubscribe, e-mail:   
> <mailto:log4j-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:log4j-user-help@jakarta.apache.org>
> 

--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>


Mime
View raw message