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 5978617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:32:29+00:00 2026-05-22T21:32:29+00:00

I want to develop indented trace for our large C++ code base that will

  • 0

I want to develop indented trace for our large C++ code base that will be perticularly helpful for developers to find the issues. I want to have indented trace functionality. E.g Consider following code:-

 void FunctionA()
{
     TR_ENTER("Function A");
     TR_PRINT("Dignostic message Function A");
     FunctionB(); // Call function B   
}

 void FunctionB()
{
    TR_ENTER("Function B");
    TR_PRINT("Dignostic message Function B");
    FunctionC(); // Call function B  
}

void FunctionC()
{
   TR_ENTER("Function C");
   TR_PRINT("Dignostic message Function C");          
}

As you can see the calls above are nested within each other. I want to generate trace log as shown below:

Function A - Start
Dignostic message Function A
     Function B - Start
     Dignostic message Function B
            Function C - Start
            Dignostic message Function C
            Function C - End
     Function B - End
Function A - End

TR_ENTER and TR_PRINT are some macros that I have use as example. To say that the function start I have use TR_ENTER and for printing some dignostic messages I have used TR_PRINT.

As you can see traces for nested function call are indented within each other. May I know is there anything already available so that I could prevent myself to work on reinventing the wheel.

Thanks,
Omky

  • 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-22T21:32:30+00:00Added an answer on May 22, 2026 at 9:32 pm

    You need to keep track of the call depth:

    class trace_entry;
    
    class trace_log {
    public:
        trace_log() : depth_(0) { }
    
    private:
        // noncopyable so we don't accidentally copy it
        trace_log(trace_log&);
        void operator=(trace_log);
    
        friend trace_entry;
    
        int depth_;
    };
    
    class trace_entry {
    public:
        trace_entry(trace_log& log, const std::string& frame)
            : log_(log), frame_(frame) {
            std::cout << std::string(4 * log.depth_, ' ') 
                      << "ENTER " << frame_ << std::endl;
            ++log_.depth_;
        }
    
        ~trace_entry() {
            --log_.depth_;
            std::cout << std::string(4 * log_.depth_, ' ') 
                      << "EXIT " << frame_ << std::endl;
        }
    private:
        // noncopyable so we don't accidentally copy it
        trace_entry(trace_entry&);
        void operator=(trace_entry);
    
        trace_log& log_;
        std::string frame_;
    };
    

    Usage example:

    void a(trace_log& log) {
        trace_entry e(log, "a");
    }
    
    void b(trace_log& log) { 
        trace_entry e(log, "b");
        return a(log);
    }
    
    int main() {
        trace_log log;
        trace_entry e(log, "main");
        b(log);
    }
    

    Output:

    ENTER main
        ENTER b
            ENTER a
            EXIT a
        EXIT b
    EXIT main
    

    This is easily extensible to support alternative forms of logging, allowing additional log messages, and just about anything else you want to do. (It would be far better to have the trace_log actually perform the logging, but for exposition purposes, this is the simplest way to demonstrate what you are trying to do.)

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

Sidebar

Related Questions

I want to develop a C++ application that will work on ALL operating systems.
I want to develop a system that will actually use sessions on jQuery mobile,
I want to develop a web service that will enable me to synchronize the
I want to develop a mobile web application using asp.net 3.5 that can be
I want to develop an application that disables the Background Data (new feature in
I want to develop an application for the android platform that can download some
I want to develop a windows service which will be accepting a datatable from
I want to develop a specific application that only clients of mine would be
I want to develop an application for Nokia 3120 . It is said that
I want to develop a program that can hide a folder. Not a hidden

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.