aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/log.cc25
-rw-r--r--lib/log.h18
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/log.cc b/lib/log.cc
new file mode 100644
index 0000000..7932e84
--- /dev/null
+++ b/lib/log.cc
@@ -0,0 +1,25 @@
+//#include <iostream.h>
+//#include <iomanip.h>
+
+#include "log.h"
+
+logbuf::logbuf(int _level) {
+ ptr = buf;
+ len = 0;
+ level = _level;
+}
+
+int logbuf::overflow(int c) {
+ if (c == '\n') {
+ *ptr++ = '\n';
+ *ptr = '\0';
+ syslog(level, buf);
+ ptr = buf;
+ return 0;
+ }
+ if ((len + 2) >= sizeof(buf))
+ return EOF;
+ *ptr++ = c;
+ len++;
+ return 0;
+}
diff --git a/lib/log.h b/lib/log.h
new file mode 100644
index 0000000..b0a2aa3
--- /dev/null
+++ b/lib/log.h
@@ -0,0 +1,18 @@
+#ifndef _log_h_
+#define _log_h_
+
+#include <ostream.h>
+#include <syslog.h>
+
+class logbuf : public streambuf {
+ public:
+ logbuf(int);
+ int overflow(int c = EOF);
+ private:
+ char *ptr;
+ int len;
+ int level;
+ char buf[1024];
+};
+
+#endif