Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7507757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:33:04+00:00 2026-05-29T22:33:04+00:00

With std::thread , it is now trivial to keep a list of threads names

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:33:05+00:00Added an answer on May 29, 2026 at 10:33 pm

    Put your thread names using MDC before setting logger in your program

     MDC::put( "threadName", threadNameString);
    

    Then at XML config

       <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%X{threadName} "/>
        </layout>
    

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one std::list<> container and these threads: One writer thread which adds elements
#include <iostream> #include <boost/thread.hpp> using std::endl; using std::cout; using namespace boost; mutex running_mutex; struct
This is about thread safety of std::map . Now, simultaneous reads are thread-safe but
My app is comprised of two threads: GUI Thread (using Qt) Simulation Thread My
So I casted boost::lexical_cast<std::string>(boost::this_thread::get_id()) this thread id to string. Now I wonder is it
I develop a module with multiple threads and one Cache in std::map. Some times
I am currently developing a basic thread pool. I used c++11's std::thread , along
I'm now creating a file transaction system (through FTP) using wxWidgets for the GUI
I have a multithreaded openCV program that uses 4 threads to do the following:
I want to debug a multi-threaded program by controlling which threads execute when. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.