logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bender Heri" <HBen...@Ergonomics.ch>
Subject RE: Passing log-time values to the Appender
Date Mon, 18 Aug 2008 09:17:51 GMT
If your calling class which knows about the involved city runs in a
separate thread context (for each city) you can use the MDC construct
which is maintained on a per thread basis. Just put your city into MDC
somewhere at the thread start when the city is known, and then in the
MultifileAppender you ask for this value again (MDC.put() and MDC.get(),
it's just a HashMap).

If you do not want to work with the not released MultifileAppender you
could also use your own RepositorySelector which is also based on the
MDC. Look the archive, was discussed a lot.

If it is always the same thread which covers different cities you cannot
use MDC for distinguishing it. You have to wrap your log message into an
own object (with members LogMessage and City) which you supply to the
log calls instead of the message (it's formally an object and not a
string). Additionally you have to provide a custom renderer for this
wrapper class which returns the embedded Message member.

Heri

> -----Original Message-----
> From: Bruno Melloni [mailto:Bruno.Melloni@wnco.com] 
> Sent: Friday, August 15, 2008 11:43 PM
> To: Log4J Users List
> Subject: RE: Passing log-time values to the Appender
> 
> This looks very promising, whether I use it as is or as the 
> basis to customize my appender further.  Thank you.  
> 
> I am still not clear as to how to submit the variables in the 
> application (about the time I call Logger.info()) so that 
> they arrive at the Appender's subAppend() method inside the 
> LoggingEvent.  Could you clarify?  I hope it is not a dumb question.
> 
> bruno
> 
> -----Original Message-----
> From: Curt Arnold [mailto:carnold@apache.org]
> Sent: Friday, August 15, 2008 3:39 PM
> To: Log4J Users List
> Subject: Re: Passing log-time values to the Appender
> 
> 
> On Aug 15, 2008, at 3:19 PM, Bruno Melloni wrote:
> 
> > I have an app that makes all Logger calls happen from a 
> single class 
> > and it uses a custom appender.  I need to modify the 
> appender so that 
> > it splits the logging to separate logs for each city.  The 
> city code 
> > is available in the calling class and is also being prefixed as the 
> > first 3 characters of every message.
> >
> > I know I could create an appender for each city... but that 
> would be 
> > insane since there are too many cities.
> >
> > I suspect that the cleanest way would be to 'somehow' pass 
> the city as
> 
> > a parameter when calling logger.info() and 'somehow' customize the 
> > appender so that it can read the value and select which 
> file to add it
> 
> > to.  Is this possible with log4j?  If so, how?
> >
> > Or, is there a better way to separate the logs?
> >
> > Thanks,
> >
> > bruno
> 
> 
> There has been intermittent activity on a MultiFileAppender which
> supports multiple open files by one appender.  It is not 
> released and  
> is subject to substantial change, but you may want to look at it.    
> See https://issues.apache.org/bugzilla/show_bug.cgi?id=45165 
> and search
> the mailing list archives for MultiFileAppender.  The source is
> available in the SVN at
> http://svn.apache.org/repos/asf/logging/sandbox/log4j/multifile
> .
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 

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


Mime
View raw message