levels.h

Go to the documentation of this file.
00001 /* Log levels.
00002  *
00003  * PegSoft log subsystem library (c) 2005 PegSoft
00004  * Contact us at pegsoft@pegsoft.net
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software (the COPYING file); if not, write to the
00017  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
00018  * USA.
00019  *
00020  */
00021 
00027 #ifndef LOG_LEVELS_H
00028 #define LOG_LEVELS_H
00029 
00030 /*************************************************************************/
00031 
00032 #include <string>
00033 
00034 /*************************************************************************/
00035 
00036 namespace xlog
00037 {
00038 
00039 /*************************************************************************/
00040 
00042 
00048 class LogLevel
00049 {
00050     public:
00052         virtual ~LogLevel() { }
00053 
00055 
00063         virtual bool operator==(std::string const &name) const
00064                 { return (!strcasecmp(name.c_str(), "All")); };
00065         
00067 
00072         virtual char const *header() const { return ""; }
00073 };
00074 
00075 /*************************************************************************/
00076 
00078 
00085 #define LOGLEVEL(classname, ancestor, llname) \
00086     class classname : public ancestor \
00087     { \
00088         public: \
00089             virtual bool operator==(std::string const &name) const \
00090             { \
00091                 if (!strcasecmp(name.c_str(), llname)) \
00092                     return true; \
00093                 return ancestor::operator==(name); \
00094             } \
00095     }
00096 
00097 /*************************************************************************/
00098 
00100 
00108 #define LOGLEVELH(classname, ancestor, llname, head) \
00109     class classname : public ancestor \
00110     { \
00111         public: \
00112             virtual bool operator==(std::string const &name) const \
00113             { \
00114                 if (!strcasecmp(name.c_str(), (llname))) \
00115                     return true; \
00116                 return ancestor::operator==(name); \
00117             } \
00118             \
00119             virtual char const *header() const { return (head); } \
00120     }
00121 
00122 /*************************************************************************/
00123 
00124 #if DEBUG
00125 LOGLEVELH(LogDebug, LogLevel, "Debug", "debug: ");
00126 #endif
00127 LOGLEVEL(LogInfo, LogLevel, "Info");
00128 LOGLEVEL(LogNotice, LogLevel, "Notice");
00129 LOGLEVELH(LogWarning, LogLevel, "Warning", "warning: ");
00130 LOGLEVELH(LogError, LogLevel, "Error", "Error: ");
00131 LOGLEVELH(LogCritical, LogLevel, "Critical", "Critical error: ");
00132 LOGLEVELH(LogFatal, LogLevel, "Fatal", "FATAL: ");
00133 
00134 /*************************************************************************/
00135 
00136 } /* namespace xlog */
00137 
00138 /*************************************************************************/
00139 
00140 #endif /* LOG_LEVELS_H */

Generated on Sun May 20 21:32:14 2007 for Epona API by  doxygen 1.4.6