Re: [Log4cplus-devel] problems displaying thread name (or understanding it)
Logging Framework for C++
Brought to you by:
wilx
From: Václav Z. <vha...@gm...> - 2013-05-15 07:46:30
|
On 14 May 2013 14:48, Alexander Dahl wrote: > Hei hei, > > I started playing around with log4cplus and wondered why I don't get > thread names displayed. Before digging to deep in my own code I had a > look at the test programs in the log4cplus source, namely thread_test. I > compiled log4cplus 1.1.1 on an up to date Debian Wheezy without any > special options when calling ./configure and get this (and more): > > % ./thread_test > main Priority: NOTSET > 0 [3049802608] WARN test.TestThread <> - Thread-3 TestThread.run()- > Starting... > 0 [3049802608] TRACE SlowObject <Thread-3 loop> - ENTER: > SlowObject::doSomething() > 1 [3049802608] INFO SlowObject <Thread-3 loop> - Actually doing > something... > 1 [3058195312] WARN test.TestThread <> - Thread-2 TestThread.run()- > Starting... > 1 [3058195312] TRACE SlowObject <Thread-2 loop> - ENTER: > SlowObject::doSomething() > 1 [3066588016] WARN test.TestThread <> - Thread-1 TestThread.run()- > Starting... > 1 [3066588016] TRACE SlowObject <Thread-1 loop> - ENTER: > SlowObject::doSomething() > 1 [3074980720] WARN test.TestThread <> - Thread-0 TestThread.run()- > Starting... > 2 [3074980720] TRACE SlowObject <Thread-0 loop> - ENTER: > SlowObject::doSomething() > 3 [3049802608] INFO SlowObject <Thread-3 loop> - Actually doing > something...1, 2, 3, testing...DONE > 3 [3058195312] INFO SlowObject <Thread-2 loop> - Actually doing > something... > 3 [3049802608] TRACE SlowObject <Thread-3 loop> - EXIT: > SlowObject::doSomething() > 3 [3049802608] TRACE SlowObject <Thread-3 loop> - ENTER: > SlowObject::doSomething() > 3 [3058195312] INFO SlowObject <Thread-2 loop> - Actually doing > something...1, 2, 3, testing...DONE > 3 [3066588016] INFO SlowObject <Thread-1 loop> - Actually doing > something... > > The part in the <> seems to contain the thread name set in > tests/thread_test/main.cxx line 100. Looking at layout.cxx a line in > this layout starts with timestamp, has some thread info in square > brackets, log level, logger name, NDC in <> and finally the message > itself. The thread info in square brackets is the pthread_t value returned by pthread_self(). > > This looks a little different than the example output on > http://log4cplus.sourceforge.net/docs/html/classlog4cplus_1_1TTCCLayout.html > which seems to have no number in square brackets but some name and no > <> at all. What's the number in the square brackets? The log snippet in the documentation is wrong. I shall fix it. The snippet comes from log4j. This is because log4cplus is derived from log4j and some of log4cplus' documentation was copy/pasted from log4j without alteration. > > This question aims how I can set some kind of thread name without using > the log4cplus thread class which is displayed with TTCC layout (or maybe > PatternLayout), but maybe I should understand the example first. At present (log4cplus 1.1.1 or earlier), the best you can get is either pthread_self() value or SYS_gettid value on Linux. I know that there are various extensions to pthreads API that allow to set and get thread names. None of them are accessible from stock log4cplus at the moment. If you need named threads, I suggest that you use the NDC or MDC facilities for that. You will have to set the thread name into NDC or MDC manually. -- VZ |