Click here to Skip to main content
6,595,854 members and growing! (19,168 online)
Email Password   helpLost your password?
Development Lifecycle » Debug Tips » General     Intermediate License: The Code Project Open License (CPOL)

CSAStatusLog - status logger

By Chris Losinger

A very simple text logger that allows you to use printf-type formatting, with automatic application name and date stamping
VC6, Dev, QA
Posted:16 Nov 1999
Updated:17 Nov 1999
Views:43,629
Bookmarked:23 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
16 votes for this article.
Popularity: 5.31 Rating: 4.41 out of 5

1
1 vote, 14.3%
2

3
2 votes, 28.6%
4
4 votes, 57.1%
5
  • Download demo project - 15 Kb

    CSAStatusLog is a very simple text logger.

    The coolest part of this little class is that, much like printf and TRACE, it allows you to use string format text : "%2.4f", "%s", etc.. It will automatically add the application name and timestamp (both optional) to each line. That saves you the trouble of doing CString::Formats or sprintfs each time you need to log something. We love it here at Smaller Animals Software.

    Sample output :

    CStatusLogDemo : 11/18/1999 16:47:43 : Howdy, stranger!
    CStatusLogDemo : 11/18/1999 16:47:43 : Did you know that 15 * 32.43 = 486.51 ?
    CStatusLogDemo : 11/18/1999 16:47:43 : Ain't that great?
    CStatusLogDemo : 11/18/1999 16:47:43 : I'm at : 0x4069b8
    CStatusLogDemo : 11/18/1999 16:47:43 : Is anyone else here?
    CStatusLogDemo : 11/18/1999 16:47:43 : Howdy! CCStatusLogDemoDlg here. 
    CStatusLogDemo : 11/18/1999 16:47:43 : My address is 0x12fe78
    CStatusLogDemo : 11/18/1999 16:47:45 : CCStatusLogDemoDlg, sayin "Good bye" 
    CStatusLogDemo : 11/18/1999 16:47:45 : (cancel)
    CStatusLogDemo : 11/18/1999 16:47:45 : Bye bye
    
    The interface is simple :
    // set the base file name ("Status.txt", for example)
    
    void	Init(const char *pOutputFilename);
    
    // output text, just like 
    
    // TRACE or printf ( log.StatusOut("%d %s", iData, lpsData); )
    
    BOOL	StatusOut(const char* fmt, ...);
    
    // turn it on or off
    
    void	Enable(BOOL bEnable);
    
    // timestamp each line?
    
    void    PrintTime(BOOL b);
    
    // print the application name?
    
    void    PrintAppName(BOOL b);
    
    // override the default app name, which is the name the EXE (minus the ".exe")
    
    void    SetAppName(const char *pName);
    

    Use it like this

    // instantiate one of these somewhere.
    
    // we usually do a single logger for the entire app.
    
    CSAStatusLog log;
    ....
    
    // start it up
    
    log.Init("Status.txt");
    log.Enable(TRUE);
    log.PrintTime(TRUE);
    log.PrintAppName(TRUE);
    
    ....
    log.StatusOut("%s, %4.2f complete", pProcedureName, fPercentComplete);
    ....
    log.StatusOut("The thingy returned %d but I was expecting %d", 
                  iReturn, iExpected);
    ....
    log.StatusOut("All hope is lost. %s has asked for %d %% of %d.", 
                   lpsDummy, iPercent, iTotal);
    ...
    

    That's it. Have fun.

  • License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    About the Author

    Chris Losinger


    Member
    Chris Losinger is the president of Smaller Animals Software, Inc..
    Occupation: Software Developer
    Location: United States United States

    Other popular Debug Tips articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
    GeneralLarge dynamic buffer support Pinmemberlamdacore23:10 28 Apr '04  
    GeneralAppend support PinsussAnonymous23:53 6 Oct '02  
    GeneralRe: Append support PinmemberWREY18:42 18 Oct '03  
    GeneralFilename and line number ? Pinmemberpelikhan3:20 25 Mar '02  
    GeneralRe: Filename and line number ? PinmemberCarlos Antollini3:50 25 Mar '02  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 17 Nov 1999
    Editor: Nick Parker
    Copyright 1999 by Chris Losinger
    Everything else Copyright © CodeProject, 1999-2009
    Web21 | Advertise on the Code Project