Click here to Skip to main content
13,357,973 members (60,378 online)
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 13 Sep 2000

Thread-safe logger with automatic removing log messages from release version.

, 13 Sep 2000
Rate this:
Please Sign up or sign in to vote.
A log file class for multi-threaded applications.
  • Download source files - 3 Kb
  • Introduction

    This class makes it possible to use log file in multi-threaded applications and has several useful features widely used in my multi-threaded, time sensitive projects where Visual C++ integrated debugger has very limited usage.

    CDebugPrintf class provides some useful features:

    1. Thread-safe logging in multi-threaded applications.
    2. Automatic removing log messages from release version of your application.
      You don't need anymore remove or comment log messages in release version. Release version will not have any overhead or unused information in executable file.
    3. You can write log messages at same time to same file from different applications.
      It is useful when it is necessary to explore interaction and timing issues between to two or more applications
    4. Using printfs style for format text: %s, %d, %4.1d and etc.
      Sorry, but there is no floating point support.
    5. Data and time stamps for each message in log file.
      Also this class provides time difference stamp from application start.
    6. Console output and easy logging for error codes returned by GetLastError function.
    7. Saving old log files.
    8. Uses only Windows API functons. So it can be used even in non-MFC applications.

    The class is easy to use.

    1. Include files dbg.h and dbg.cpp to your project.
    2. At any time you want to write something to the log file, use the PRINTF macro.

    Example of log file output:

    0.000 08/25/2000 15:04:48  User name = KVA
    0.015 08/25/2000 15:04:48  ISAPI = "TraxDataMgr.dll"
    0.015 08/25/2000 15:04:48  CActionHandler constructor
    0.015 08/25/2000 15:04:48  CDataMgrActionHandler constructor
    5.123 08/25/2000 15:04:53  0   HttpExtensionProc: started
    5.123 08/25/2000 15:04:53  Execute request 1 started.   
    5.672 08/25/2000 15:04:53  CIndexer constructor: done
    5.693 08/25/2000 15:04:53  Open:  D:\Data\Docs\customer
    5.693 08/25/2000 15:04:53  Loading index table from 'D:\Data\Docs\customer.idx'
    5.693 08/25/2000 15:04:53  Count: 93560
    6.132 08/25/2000 15:04:54  Index loading finished ... OK
    6.375 08/25/2000 15:04:54  Execute request 1 finished.   
    6.375 08/25/2000 15:04:54  0   HttpExtensionProc: finished

    Class usage:

    void SomeFunction( char* arg1, int arg2, string& arg3 )
        // doing something
        PRINTF("Something happened by using %s and %d arguments", arg1, arg2);
        // doing something
        PRINTF("This message is visible on console and in log-file.");


    All log messages must fit into one line of source code because of problem with transparent removing log messages from release version.
    PRINTF("One line messages are supported.");
    PRINTF("Multi-line messages %s %s",
               "are not",


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Vlad Kirienko
    United States United States
    No Biography provided

    You may also be interested in...


    Comments and Discussions

    Questioncan this be used in Linux Project Pin
    pkuwgg8-Sep-08 17:25
    memberpkuwgg8-Sep-08 17:25 
    GeneralWorks great! Pin
    Luckymmkay31-Aug-07 5:39
    memberLuckymmkay31-Aug-07 5:39 
    GeneralPossible memory corruption Pin
    Tnarol6-Jul-06 3:17
    memberTnarol6-Jul-06 3:17 
    GeneralAn enhancement to class Pin
    Wes Jones13-Jun-01 10:31
    memberWes Jones13-Jun-01 10:31 
    GeneralProblems w/ Console window Pin
    Wes Jones24-May-01 16:25
    memberWes Jones24-May-01 16:25 
    GeneralRe: Problems w/ Console window - half way fixed! Pin
    Wes Jones25-May-01 14:33
    memberWes Jones25-May-01 14:33 
    GeneralShouldn't CDebugPrintf::HideConsole() be... Pin
    Anonymous8-Feb-01 12:48
    memberAnonymous8-Feb-01 12:48 
    GeneralFix for Multi-Line comment Pin
    Brad Bruce14-Sep-00 13:10
    sussBrad Bruce14-Sep-00 13:10 
    GeneralAdd ThreadID Pin
    Mark Findlay14-Sep-00 10:59
    sussMark Findlay14-Sep-00 10:59 
    GeneralRe: Add ThreadID Pin
    James Spibey21-Dec-00 23:25
    memberJames Spibey21-Dec-00 23:25 
    GeneralRe: Add ThreadID Pin
    Anonymous17-Apr-01 4:43
    memberAnonymous17-Apr-01 4:43 
    GeneralRe: Add ThreadID Pin
    Spacer25-Nov-01 1:21
    memberSpacer25-Nov-01 1:21 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.180111.1 | Last Updated 14 Sep 2000
    Article Copyright 2000 by Vlad Kirienko
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid