00001 /* 00002 * Time-stamp: <00/03/05 05:11:26 pagey> 00003 * 00004 * $Format: " * $Id: errlog.h,v 0.0.0.1 2000/06/30 01:58:24 pagey Exp $"$ 00005 * errlog.h 1.2 Mon, 06 Mar 2000 01:44:21 -0800 pagey 00006 * 00007 */ 00008 // 00009 // FILE: errlog.h 00010 // 00011 // FUNCTION: 00012 // The linErrLog class provides some simple error logging 00013 // facilities. It should be realtively easily extensible 00014 // to provide more extensive services. 00015 // 00016 // USAGE: 00017 // Classes wishing to use this error reporting & debugging 00018 // framework should inherit from this class. Six levels 00019 // of logging are provided: Fatal, Severe, Warning, 00020 // Informational, Debug and Trace. The logging level 00021 // can be changed dynamically at runtime. Logging can be 00022 // enabled and disabled at runtime. If desired, logging 00023 // can be compiled out of the application. 00024 // 00025 // METHODS: 00026 // The SetLogLevel() method sets the error logging severity 00027 // level 00028 // 00029 // The GetLogLevel() method returns the currnt error 00030 // logging severity level. 00031 // 00032 // The Enable() method enables logging. 00033 // The Disable() method disables logging. 00034 // 00035 // The SetScope() method should be used to declare the 00036 // current scope. Typically, it should be called 00037 // at the begining of a soubroutine, method or large 00038 // block and should name that block. The scope is 00039 // printed with the error message. 00040 // 00041 // The PrtErr() method prints a message to the log file. 00042 // The message is prefixed with a printed severity 00043 // level, and the current scope. The first argument 00044 // to this method indicates the severity level of the 00045 // message; it is used to avoid the printing of 00046 // low-severity messages. The second and further 00047 // arguments are identical to the arguments of the 00048 // printf() function. 00049 // 00050 // This method should not be used directly; instead, 00051 // the LOGERR macro should be used instead. 00052 // 00053 // The PrtMore() method prints a message to the log file. 00054 // The first argument to this method indicates the 00055 // severity level of the message; it is used to avoid 00056 // the printing of low-severity messages. The second 00057 // and further arguments are identical to the arguments 00058 // of the printf() function. 00059 // 00060 // SUGGESTED ENHANCEMENTS: 00061 // -- Provide Internationalization framework. 00062 // -- Allow a logfile or pipe to be specified. 00063 // -- Allow printing to syslogd. 00064 // -- Provide locking mechanism to enable the use 00065 // in a multi-porcess environment. 00066 // 00067 // HISTORY: 00068 // Copyright (c) 1995, 1997 Linas Vepstas linas@linas.org 00069 // Released under the conditions of the GNU General 00070 // Public License. 00071 00072 #ifndef __LIN_ERR_LOG_H__ 00073 #define __LIN_ERR_LOG_H__ 00074 00075 #include <stdio.h> 00076 00077 class linErrLog { 00078 protected: 00079 enum severity { 00080 FATAL, 00081 SEVERE, 00082 WARN, 00083 INFO, 00084 TRACE, 00085 DEBUG 00086 }; 00087 public: 00088 linErrLog (void); 00089 ~linErrLog (); 00090 00091 void Enable (void) { enabled = 1; }; 00092 void Disable (void) {enabled = 0; }; 00093 void SetLogLevel (severity); 00094 severity GetLogLevel (void); 00095 00096 void SetScope (const char * scp) { scope = scp; } 00097 00098 void PrtErr (severity, char * fmt, ...); 00099 void PrtMore (severity, char * fmt, ...); 00100 00101 protected: 00102 short enabled; // error printeing enabled? 00103 severity loglevel; // logging level 00104 const char * scope; // name of scope 00105 FILE * errf; // output file 00106 00107 }; 00108 00109 #define LIN_COMPILE_IN_DIAGNOSTICS 00110 #ifdef LIN_COMPILE_IN_DIAGNOSTICS 00111 #define LOGERR(x) PrtErr x 00112 #define LOGMORE(x) PrtMore x 00113 #define SETSCOPE(x) SetScope(x) 00114 #else 00115 #define LOGERR(x) 00116 #define LOGMORE(x) 00117 #define SETSCOPE(x) 00118 #endif /* LIN_COMPILE_IN_DIAGNOSTICS */ 00119 00120 #endif /* __LIN_ERR_LOG_H__ */ 00121 00122 // ================== END OF FILE =============================