Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

logs.h

Go to the documentation of this file.
00001 /********************************************************************
00002     Copyright (c) 2001, Lee Patterson & Ant Works Software
00003     http://ssobjects.sourceforge.net
00004 
00005     created  :      9/21/1999
00006     filename :      logs.h
00007     author   :      Lee Patterson
00008     
00009     purpose  :      Enables the logging of a function being enter, and when 
00010                     the function returns, no matter how it returns.
00011               
00012                     Just make a call to         logs:Init("appname.log");
00013               
00014                     The define at the top of    logs func("myfunc");
00015                     your function like this:    
00016               
00017               
00018                     Example:
00019               
00020                         void myfunc()
00021                         {
00022                             logs func("myfunc");    //a logs contructor
00023                             //do something
00024                         }
00025               
00026                         void main()
00027                         {
00028                             logs::Init("mylog.log");            //set the log filename, init memory
00029                             logs::log("starting program");
00030                             myfunc();
00031                             logs::log("ending");
00032                             logs::Deinit();                     //free memory
00033                         }
00034               
00035               
00036                     This example will generate the following in the log file:
00037               
00038                         starting program
00039                         myfunc ENTER
00040                         myfunc RETURNING
00041                         ending
00042 
00043 *********************************************************************/
00044 
00045 #ifndef LOGS_H
00046 #define LOGS_H
00047 
00048 #include "msdefs.h"
00049 
00050 namespace ssobjects
00051 {
00052 //TODO: need to add "ssobjects::" to defines
00053 
00054 #define LOG ssobjects::logs::logln
00055 
00056 #ifdef DEBUG
00057 #define ENABLELOG ssobjects::logs::enable
00058 #define INITLOG ssobjects::logs::init
00059 #define DLOG ssobjects::logs::logln
00060 #define DUMP ssobjects::logs::dump
00061 #define FUNCLOG ssobjects::logs func
00062 #else
00063 #define DLOG 1 ? (void)0 : ssobjects::logs::log
00064 #define FUNCLOG(x)
00065 #define INITLOG(x)
00066 #define ENABLELOG 1 ? (void)0 : ssobjects::logs::enable 
00067 #define DUMP 1 ? (void)0 : ssobjects::logs::dump
00068 #endif
00069 
00070 class logs
00071 {
00072   public:
00073     enum {L_FILE=1,L_CONSOLE=2,L_DEFAULT=3,L_NONE=0,L_ALL=0xFFFFFFFF};
00074     logs(const char *pFuncName);
00075     ~logs();
00076 
00077   public:
00078     static void log(const char* fmt,...);
00079     static void logln(const char* fmt,...);
00080     static void dump(void* pMemory,DWORD dwNumBytes);
00081     static void init(const char* pszLogFileName);
00082     static void deinit();
00083     static void enable(bool bEnable=true);
00084     static void set(unsigned nSet,unsigned nReset=0);
00085 
00086     enum{max_funcs=100,max_func_len=80};
00087 
00088   public:
00089     static bool m_bActive;
00090     static unsigned m_nFlags;
00091     static bool m_bInited;
00092 
00093   private:
00094     static bool isPrintable(int c);
00095     static unsigned m_nTail;
00096     static char *m_pszFileName;
00097     static char m_szFuncName[max_funcs][max_func_len];
00098 };
00099 
00100 };
00101 
00102 #endif

Generated on Thu Nov 8 12:39:25 2001 for SimpleServerObjects by doxygen1.2.11 written by Dimitri van Heesch, © 1997-2001