summaryrefslogtreecommitdiff
path: root/src/syslogdevice.cc
diff options
context:
space:
mode:
authorErwin Hoffmann <feh@fehcom.de>2023-09-21 17:36:16 +0200
committerErwin Hoffmann <feh@fehcom.de>2023-09-21 17:36:16 +0200
commit44388ac49531af9e2565f76ef99ff7afb757b3fb (patch)
tree4eeb294db5bc3dbd075d0df5fea13c664cc331e2 /src/syslogdevice.cc
parent889d69a87d51c8df531885cf1ac3d12d64a0cff7 (diff)
all sources
Diffstat (limited to 'src/syslogdevice.cc')
-rw-r--r--src/syslogdevice.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/syslogdevice.cc b/src/syslogdevice.cc
new file mode 100644
index 0000000..927416e
--- /dev/null
+++ b/src/syslogdevice.cc
@@ -0,0 +1,75 @@
+/** --------------------------------------------------------------------
+ * @file syslogdevice.cc
+ * @brief Implementation of the SyslogDevice class.
+ * @author Andreas Aardal Hanssen
+ * @date 2002, 2003
+ * ----------------------------------------------------------------- **/
+#include "syslogdevice.h"
+#include <string>
+
+#include <syslog.h>
+
+using namespace ::std;
+using namespace ::Binc;
+
+//------------------------------------------------------------------------
+string SyslogDevice::ident;
+
+//------------------------------------------------------------------------
+SyslogDevice::SyslogDevice(int f, const char *i, int o, int fa)
+ : IODevice(f), option(o), facility(fa), priority(LOG_INFO)
+{
+ ident = i;
+ openlog(ident.c_str(), option, facility);
+}
+
+//------------------------------------------------------------------------
+SyslogDevice::~SyslogDevice(void)
+{
+ closelog();
+}
+
+//------------------------------------------------------------------------
+string SyslogDevice::service(void) const
+{
+ return "log";
+}
+
+//------------------------------------------------------------------------
+bool SyslogDevice::waitForWrite(void) const
+{
+ return true;
+}
+
+//------------------------------------------------------------------------
+bool SyslogDevice::waitForRead(void) const
+{
+ return false;
+}
+
+//------------------------------------------------------------------------
+IODevice::WriteResult SyslogDevice::write(void)
+{
+ string out;
+ string::const_iterator i = outputBuffer.str().begin();
+ string::const_iterator ie = outputBuffer.str().end();
+
+ for (; i != ie; ++i) {
+ if (*i == '\n') {
+ syslog(priority, out.c_str(), out.size());
+ out = "";
+ } else if (*i != '\r')
+ out += *i;
+ }
+
+ if (out != "") syslog(priority, out.c_str(), out.size());
+
+ outputBuffer.clear();
+ return WriteDone;
+}
+
+//------------------------------------------------------------------------
+bool SyslogDevice::fillInputBuffer(void)
+{
+ return false;
+}