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

Logger.h

Go to the documentation of this file.
00001 #ifndef _Logger_h_
00002 #define _Logger_h_
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <string>
00007 
00008 #include "config.h"
00009 
00010 #ifndef HAVE_SYSLOG_H
00011 #undef WITH_SYSLOG
00012 #endif
00013 
00014 #ifdef WITH_SYSLOG
00015 #include<syslog.h>
00016 #endif
00017 
00018 using std::string;
00019 
00033 class Logger {
00034 
00035 #ifndef WITH_SYSLOG
00036         std::ofstream log;
00037 #endif
00038 
00039         int _priority;
00040 
00041         char *buf;
00042         int buflen, bufsz;
00043 
00044         int bufresize(int sz);
00045         void append(const char *s);
00046         void print();
00047 
00048       public:
00049 #ifdef WITH_SYSLOG
00050         enum { Emergency = LOG_EMERG,
00051                 Alert = LOG_ALERT,
00052                 Critical = LOG_CRIT,
00053                 Error = LOG_ERR,
00054                 Warning = LOG_WARNING,
00055                 Notice = LOG_NOTICE,
00056                 Info = LOG_INFO,
00057                 Debug = LOG_DEBUG
00058         };
00059         enum { Cons = LOG_CONS,
00060                 NDelay = LOG_NDELAY,
00061 #ifdef LOG_PERROR
00062                 PError = LOG_PERROR,
00063 #else
00064                 PError = 0,
00065 #endif
00066 #ifdef LOG_NOWAIT
00067                 NoWait = LOG_NOWAIT,
00068 #else
00069                 NoWait = 0,
00070 #endif
00071                 Pid = LOG_PID
00072         };
00073 #else
00074         enum { Emergency = 0,
00075                 Alert = 1,
00076                 Critical = 2,
00077                 Error = 3,
00078                 Warning = 4,
00079                 Notice = 5,
00080                 Info = 6,
00081                 Debug = 7
00082         };
00083 #endif
00084 
00085 #ifdef WITH_SYSLOG
00086         Logger();
00087         void open(char *ident, int option, int facility);
00088 #else
00089         Logger(char *fn = NULL, int option = 0);
00090         void open(char *fn);
00091 #endif
00092         ~Logger();
00093 
00094         void close();
00095 
00096         Logger & priority(int p);
00097         Logger & p(int p) {
00098                 return priority(p);
00099         } Logger & write(const char *s);
00100         Logger & write(char ch) {
00101                 char buf[2];
00102                 buf[0] = ch;
00103                 buf[1] = '\0';
00104                 return write(buf);
00105         }
00106 
00107         friend Logger & operator<<(Logger & l, const char *s);
00108         friend Logger & operator<<(Logger & l, const string & s);
00109         friend Logger & operator<<(Logger & l, char ch);
00110         friend Logger & operator<<(Logger & l, unsigned int i);
00111         friend Logger & operator<<(Logger & l, int i);
00112 };
00113 
00114 #endif

Generated on Sun Oct 24 21:08:17 2004 for NewsCache by doxygen 1.3.6-20040222