With std::thread, it is now trivial to keep a list of threads names in the program state (either by wrapping the thread, or by using a singleton to manage the thread list.)
I am starting to use log4cxx for my logging, and I’d like to have it display the thread name. However, this means I cannot use the PatternLayout. The thread numbers aren’t very useful on their own.
What is the best way to do this? Am I stuck with just outputting a map, or can I override PatternLayout/ConversionPattern in a clever way to do what I want? And if I overload it, how do I point to the class in the config file? Or can I possibly add a conversion character?
Put your thread names using MDC before setting logger in your program
Then at XML config
So at each log message your thread name will apear.
For more info check answer of this question: Add process id to log file name in log4cxx