logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Li YuanHao" <li_yuan...@hotmail.com>
Subject Re:Re: can each thread has a logfile?
Date Tue, 03 Dec 2002 10:07:12 GMT
Thank you very much!
You give me great help.

----- Original Message -----
From: "Thomas Muller" <ttm@online.no>
To: "Log4J Users List" <log4j-user@jakarta.apache.org>
Sent: Tuesday, December 03, 2002 6:39 PM
Subject: RE: can each thread has a logfile?


> Li,
>
> As far as I understand log4j has no built-in mechanism aimed at
facilitating
> what you ask for, but it's not hard to code this functionality yourself.
You
> can e.g. use java.lang.ThreadLocal.
>
> public class Foo {
>
>    private static final ThreadLocal THREAD_LOCAL_LOGGER = new
ThreadLocal()
> {
>
>             protected synchronized Object initialValue() {
>                 String name = Thread.currentThread().getName();
>                 Logger logger = Logger.getLogger( name );
>                 logger.addAppender( new FileAppender( "%d{ABSOLUTE} %m%n",
>                      System.getProperty( "user.dir" ) + File.separator +
> name, false ) );
>                 return logger;
>             }
>
>             public void set( Object o ) {
>                 throw new UnsupportedOperationException();
>             }
>        };
>
>    // Returns thread local logger
>    private static Logger getLogger() {
>        return ( Logger ) THREAD_LOCAL_LOGGER.get();
>    }
>
>    public void doSomething() {
>       getLogger().debug( "foobar" );
>       // (.....)
>    }
>
> }
>
> Hope this helps,
>
> --
>
> Thomas
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> | -----Original Message-----
> | From: Li YuanHao [mailto:li_yuanhao@hotmail.com]
> | Sent: 03 December 2002 01:07
> | To: Log4J Users List
> | Subject: Re: can each thread has a logfile?
> |
> |
> |  Hi,Could anyone tell me THAT whether I can configure log4j to log each
> |  thread to each self logfile?
> |  Could you give a sample?
> |  Any advice is appreciated .
> |
> | --
> | To unsubscribe, e-mail:
> | <mailto:log4j-user-unsubscribe@jakarta.apache.org>
> | For additional commands, e-mail:
> | <mailto:log4j-user-help@jakarta.apache.org>
> |
> |
>
>
>
> *************************************************************************
> Copyright ERA Technology Ltd. 2002. (www.era.co.uk). All rights reserved.
> The information supplied in this Commercial Communication should be
treated
> in confidence.
> No liability whatsoever is accepted for any loss or damage
> suffered as a result of accessing this message or any attachments.
>
> ________________________________________________________________________
> This email has been scanned for all viruses by the MessageLabs SkyScan
> service. For more information on a proactive anti-virus service working
> around the clock, around the globe, visit http://www.messagelabs.com
> ________________________________________________________________________
>
> --
> 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