deLogger.h

Go to the documentation of this file.
00001 /* Copyright (c) 2005 Arachi, Inc. and Stanford University.
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining
00004  * a copy of this software and associated documentation files (the
00005  * "Software"), to deal in the Software without restriction, including
00006  * without limitation the rights to use, copy, modify, merge, publish,
00007  * distribute, sublicense, and/or sell copies of the Software, and to
00008  * permit persons to whom the Software is furnished to do so, subject
00009  * to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00018  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00019  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00020  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00021  */
00022 
00023 #ifndef _DELOGGER_H
00024 #define _DELOGGER_H
00025 
00026 #include <stdio.h>
00027 
00028 #include "deTypes.h"
00029 
00035 //      @{
00036 #define DFL_ERROR deLogger::_DFL_ERROR
00037 #define DFL_WARN  deLogger::_DFL_WARN
00038 #define DFL_INFO  deLogger::_DFL_INFO
00039 #define DFL_DEBUG deLogger::_DFL_DEBUG
00040 //      @}
00041 
00046 //      @{
00047 #define dePrintf deLogger::Printf
00048 #define deLog deLogger::Log
00049 //      @}
00050 
00051 class deLogger;
00056 class deLoggerOutput
00057 {
00058         friend class deLogger;
00059 public:
00060         deLoggerOutput() 
00061         {
00062                 next = NULL;
00063         }
00064 
00065         virtual ~deLoggerOutput()
00066         {
00067                 if (next) delete next;
00068         }
00069 
00070         virtual void Log(deChar *msg) = NULL;
00071 
00072 protected:
00073         deLoggerOutput *next;
00074 };
00075 
00080 class deLoggerOutputStd : public deLoggerOutput
00081 {
00082 public:
00083         virtual void Log(deChar *msg);
00084 };
00085 
00086 #ifdef WIN32
00087 
00091 class deLoggerOutputWinDebug : public deLoggerOutput
00092 {
00093 public:
00094         virtual void Log(deChar *msg);
00095 };
00096 #endif
00097 
00102 class deLoggerOutputFile : public deLoggerOutput
00103 {
00104 public:
00105         deLoggerOutputFile(deChar* filename);
00106         ~deLoggerOutputFile();
00107 
00108         virtual void Log(deChar *msg);
00109 
00110 private:
00111         FILE *logfile;
00112 };
00113 
00121 class deLogger
00122 {
00123 public:
00125         enum 
00126         {
00127                 _DFL_ERROR = 1,
00128                 _DFL_WARN,
00129                 _DFL_INFO,
00130                 _DFL_DEBUG
00131         };
00132 
00133         deLogger();
00134         virtual ~deLogger();
00135 
00136         static void Initialize();
00137         static void Shutdown();
00138 
00139         static void Format(deChar *buf, deInt type, deChar* category, deChar *msg);
00140         static void Log(deInt type, deChar* category, deChar* format, ...);
00141         static void Printf(deChar* format, ...);
00142 
00143         static void AddOutput(deLoggerOutput *out);
00144 
00145 private:
00146         static deLogger* logger;
00147 
00148         deLoggerOutput *output;
00149 };
00150 
00151 #endif // _DELOGGER_H

Generated on Sun Apr 9 22:12:42 2006 for TAO by  doxygen 1.4.6-NO