You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by se...@desjardins.com on 2002/11/22 21:21:31 UTC

Réf. : %t always returns "main"

Daniel,
in your main(), shouldn't you do a  "lt.start()" instead of calling directly "lt.run()"?
Serge Arsenault




Daniel.Hannum@smed.com on 2002-11-22 15:07:12

Veuillez répondre à "Log4J Users List" <lo...@jakarta.apache.org>

Pour : "Log4J Users List" <lo...@jakarta.apache.org>
cc :
Objet :     %t always returns "main"



Hi. Pardon the stupid question: I can't seem to make the %t (ThreadName)
field work in PatternLayout. It appears to print "main" even if I make the
logging call from a thread with a different name.

Here is my code

// my test logging class
public class PrototypeTest {

  public static void main(String args[]) {
    LogThread lt = new LogThread("My_new_thread");
    lt.run();
  }
}

class LogThread extends Thread {

  LogThread(String name) {
    super(name);
  }

  public void run() {
    DOMConfigurator.configureAndWatch("local.xml", 2000);
    Logger root = Logger.getRootLogger();
    root.error("foo");
  }
}

local.xml is trivial. It attaches a ConsoleAppender to the root, and the
Layout is the default (which contains %t).

Even though I spawned a new thread with the name "My_new_thread", Log4j
says the thread is "main". If I do this.getName() inside run(), it returns
the proper name.

I think if %t just didn't work, people would have noticed, so maybe someone
can point out the flaw in my code.

Thank you

Daniel Hannum




-------------------------------------------------------------------------------
This message and any included attachments are from Siemens Medical Solutions
Health Services Corporation and are intended only for the addressee(s).
The information contained herein may include trade secrets or privileged or
otherwise confidential information.  Unauthorized review, forwarding, printing,
copying, distributing, or using such information is strictly prohibited and may
be unlawful.  If you received this message in error, or have reason to believe
you are not authorized to receive it, please promptly delete this message and
notify the sender by e-mail with a copy to CSOffice@smed.com.  Thank you



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>










--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>