c++ vs2003 loging the program jumps from function to function

I was wondering if there was a way to log which function is called and i what order from start to completion
is there any way this can be done
running vs2003 enterprise
thanks for your help
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Karrtik IyerSoftware ArchitectCommented:
Do you mean you want to log the call stack of your program?
Karrtik IyerSoftware ArchitectCommented:
We have used many techniques in past to get the log of exact flow of our program (trace of function calls and in what order they were called and also trace the inputs/outputs of each function call).

1> During debugging the code we have used one of Visual studio's debugging window call stack (Debugging ->Windows -> Call stack)
2> In primitive days of our development, we even logged every in/out of each function to a log file, using/creating simple object on stack as first line of each function which takes function name as its input in the constructor, and in this stack object's constructor and destructor we used to log the details to a file. Something like Fn name --> In and Fn name --> Out. We also used to write this log at a different log level so that every time this is not logged.Only if log level is set to certain value this shall be logged to reduce the load on logging.
3> In windows we have used techniques as discussed in the below article to dump the call stack at any point.

Please let me know what exactly you are looking for and we can help you better.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
class FunctionLog
      static const char * szLogFile;
      static CRITICAL_SECTION cslog;
      static bool logFileReady;

      std::string strFunction;
      FunctionLog(const char * szFunction)
          : strFunction(szFunction)
#ifdef DEBUG
            log(true, szFunction);
#ifdef DEBUG
            log(false, strFunction.c_str());
      static void log(bool enter, const char * szfunction)
             static std::ofstream logfile;
             if (!logFileReady)
                  logfile.open(szLogFile, std::ios::out);
                  if (!logfile.is_open())
            logFileReady = true;
                 logfile << strFunction;
                 if (enter)
                    logfile <<  " entered" << std::endl;
                   logfile <<  " left" << std::endl;

Open in new window

you need to initialize the static members in a cpp file. then create an instance of FunctionLog at begin of each function you want to log.

of course you could enhance the logging by passing more arguments. you also could have a variable argument logging by passing a std::ostringstream by reference as argument. that would allow like

void MyClass::MyFunction(int n, char * text)
        std::ostringstream oss;
        FunctionLog("MyClass::MyFunction", (((std::ostream &)oss) << "n = " << n << "  text = " << text));

Open in new window

sydneyguyAuthor Commented:
thanks for this may be a bit too much info for what i am needing as i do not wish to take in all the mouse moves or clicks to things that i am not requiring tokeep a track of but i am sure this will come in handy later down the track so thanks you so much for all your help and comments.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.