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:[EMAIL PROTECTED]]
| 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:[EMAIL PROTECTED]>
| For additional commands, e-mail:
| <mailto:[EMAIL PROTECTED]>
|
|



*************************************************************************
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:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to