I'm evaluating log4cplus for a multi threaded C++ application on linux. The TTCCLayout and the PatternLayout allow the thread name to be displayed. In my tests there was never a name but just a meaningless number. I'm not using the thread class of log4cplus. How does log4cplus determine this thread name and is it possible to set it myself?
Asked
Active
Viewed 1,017 times
0
-
duplicate of http://stackoverflow.com/q/778085/841108 – Basile Starynkevitch May 14 '13 at 10:08
-
I guess it's not that easy. I had to dig through my thread library and successfully used prctl to set a name, but no effect. Even the test application in the log4cplus source does not show thread names. Maybe I should ask this on the log4cplus devel mailing list. – LeSpocky May 14 '13 at 11:15
-
http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html – Basile Starynkevitch May 14 '13 at 11:29
1 Answers
2
Log4cplus (as of version 1.1.1 or earlier) does not have any PatternLayout formatter for thread names. It only has two thread related formatters:
%t
- prints thread ID; for *nix, it is whatever valuepthread_t
represents, usually anint
value or a pointer value%T
- prints alternative thread ID; for Linux, prints the value returned bysyscall (SYS_gettid)
There is definitely some room for improvement.

wilx
- 17,697
- 6
- 59
- 114
-
You're right and that's what I was told now [on the log4cplus mailing list](http://sourceforge.net/mailarchive/forum.php?thread_name=CAKw7uVhT9_xEac_svRUmtLuLqhW_yohzvRQXtQzt5rvSXC5VTw%40mail.gmail.com&forum_name=log4cplus-devel) as well. However there are NDC or MDC facilities I could use. I'll have another look in the log4cplus code for that. O:-) Thanks for your help. :-) – LeSpocky May 15 '13 at 11:45