diff options
Diffstat (limited to 'project2/common/loggers.h')
-rw-r--r-- | project2/common/loggers.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/project2/common/loggers.h b/project2/common/loggers.h new file mode 100644 index 0000000..69b352c --- /dev/null +++ b/project2/common/loggers.h @@ -0,0 +1,60 @@ +#ifndef LOGGERS_H +#define LOGGERS_H + +#include "logger.h" + +/// Base class for classes providing a logging facility +class LogDriverBase : public virtual IntrusivePtrBase { + public: + LogDriverBase(int level); + virtual ~LogDriverBase(); + + virtual void message(int priority, const char * msg) const = 0; + const int level; +}; + +/// Base class for loggers that write to some sort of file handle +class FileBasedLogDriver : public LogDriverBase { + public: + FileBasedLogDriver(FILE *, int level, bool timestamp); + virtual ~FileBasedLogDriver() = 0; + + virtual void message(int priority, const char * msg) const; + + protected: + void writeTimestamp() const; + void writeLevel(int level) const; + FILE * file; + bool timestamp; + + private: + const char * timeStr() const; + mutable char tmbuf[30]; +}; + +/// Logger that writes to the console +class ConsoleLogDriver : public FileBasedLogDriver { + public: + ConsoleLogDriver(FILE *, int level, bool timestamp); + ~ConsoleLogDriver(); + +}; + +/// Logger that writes to a file +class FileLogDriver : public FileBasedLogDriver { + public: + FileLogDriver(const char * path, int level); + ~FileLogDriver(); +}; + +/// Logger that writes to syslog +class SyslogLogDriver : public LogDriverBase { + public: + SyslogLogDriver(const char * ident, int level, int option = 0, int facility = LOG_USER); + virtual ~SyslogLogDriver(); + + virtual void message(int priority, const char * msg) const; +}; + +#endif + |