CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Trace Macro

Threaded View

  1. #1
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Trace Macro

    I have a Trace.h file which is include in pretty much all my files, which contains the following:

    Code:
    #ifndef TRACE_H_INCLUDED
    #define TRACE_H_INCLUDED
    
    #include <iostream>
    #include <fstream>
    
    static std::ofstream log_stream("output.log");
    
    #define TRACE(ARG) if(true){log_stream << __FILE << " at line " << __LINE << ARG << std::endl;} else void(0)
    
    #endif // TRACE_H_INCLUDED
    Basically, the idea is I can log stuff to a file as my program runs.

    The problem is that after running my program, I realize that a good amount of my traces are missing, most are out of order, and finally, a lot of them are missing the beginning or end of the message, like this:

    Code:
    /main.cpp at line 28 there
    ne 33 here
    /EnColor.h at line 33 hello
    What am I doing wrong? I thought std::endl was supposed to flush my stream, doesn't that mean this shouldn't happen?

    Do I have a broken declaration of log_stream, and actually have several handles on the same file?

    Is this an ofstream problem, or what? What would you guys do?

    PS: Codeblocks with mingw on winxp32
    PS2, replacing log_stream with the standard std::cout works fine, but that is not what I want
    Last edited by monarch_dodra; January 28th, 2010 at 12:30 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured