summaryrefslogtreecommitdiff
path: root/project2/common/loggers.h
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-08-31 21:48:04 +0000
committerrandomdan <randomdan@localhost>2011-08-31 21:48:04 +0000
commit05b8bed896e5fe8c1841869e5d6e8e837e72c10a (patch)
tree77abf662b898321a61058fb0a0da603e336bcad9 /project2/common/loggers.h
parentAdds RDBMS table caching solution (diff)
downloadproject2-05b8bed896e5fe8c1841869e5d6e8e837e72c10a.tar.bz2
project2-05b8bed896e5fe8c1841869e5d6e8e837e72c10a.tar.xz
project2-05b8bed896e5fe8c1841869e5d6e8e837e72c10a.zip
The big reshuffle
Diffstat (limited to 'project2/common/loggers.h')
-rw-r--r--project2/common/loggers.h60
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
+