summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-08-05 20:15:03 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2019-08-05 20:25:15 +0100
commit3b38c04209ba45e19df62f4f89aa2d20c04846d4 (patch)
treeb66925f6f688589c5c8468f584c33322f7677774
parentMove width limited domain writer to a general location (diff)
downloadicetray-0.4.1.tar.bz2
icetray-0.4.1.tar.xz
icetray-0.4.1.zip
Add syslog log writericetray-0.4.1
-rw-r--r--icetray/icetray/logWriterSyslog.cpp35
-rw-r--r--icetray/icetray/logWriterSyslog.h21
-rw-r--r--icetray/unittests/testIceTrayLogger.cpp7
3 files changed, 63 insertions, 0 deletions
diff --git a/icetray/icetray/logWriterSyslog.cpp b/icetray/icetray/logWriterSyslog.cpp
new file mode 100644
index 0000000..d78da5b
--- /dev/null
+++ b/icetray/icetray/logWriterSyslog.cpp
@@ -0,0 +1,35 @@
+#include <logWriter.h>
+#include "logWriterSyslog.h"
+#include <syslog.h>
+
+// NOLINTNEXTLINE(modernize-concat-nested-namespaces)
+namespace IceTray {
+ namespace Logging {
+ AdHocFormatter(LogMsg, "%D: %?");
+ SyslogLogWriter::SyslogLogWriter(const Ice::PropertiesPtr & p) :
+ AbstractLogWriter("logging.syslog", p),
+ width(p ? p->getPropertyAsIntWithDefault("logging.syslog.width", -1) : -1)
+ {
+ if (p) {
+ openlog(
+ p->getPropertyWithDefault("logging.syslog.ident", "icetray").c_str(),
+ p->getPropertyAsIntWithDefault("logging.syslog.option", 0),
+ p->getPropertyAsIntWithDefault("logging.syslog.facility", LOG_DAEMON));
+ }
+ }
+
+ SyslogLogWriter::~SyslogLogWriter()
+ {
+ closelog();
+ }
+
+ void
+ SyslogLogWriter::message(LogLevel priority, Domain domain, const std::string_view message, const Ice::Current &)
+ {
+ syslog((int)priority, "%s", LogMsg::get(width, domain, message).c_str());
+ }
+
+ FACTORY(SyslogLogWriter, LogWriterFactory);
+ }
+}
+
diff --git a/icetray/icetray/logWriterSyslog.h b/icetray/icetray/logWriterSyslog.h
new file mode 100644
index 0000000..fdce2ec
--- /dev/null
+++ b/icetray/icetray/logWriterSyslog.h
@@ -0,0 +1,21 @@
+#ifndef ICETRAY_LOGGING_SYSLOG_H
+#define ICETRAY_LOGGING_SYSLOG_H
+
+#include "logger.h"
+
+namespace IceTray {
+ namespace Logging {
+ class SyslogLogWriter : public AbstractLogWriter {
+ public:
+ SyslogLogWriter(const Ice::PropertiesPtr & p);
+ ~SyslogLogWriter();
+
+ void message(LogLevel priority, Domain domain, std::string_view message, const Ice::Current &) override;
+
+ const int width;
+ };
+ }
+}
+
+#endif
+
diff --git a/icetray/unittests/testIceTrayLogger.cpp b/icetray/unittests/testIceTrayLogger.cpp
index 0998143..73142a4 100644
--- a/icetray/unittests/testIceTrayLogger.cpp
+++ b/icetray/unittests/testIceTrayLogger.cpp
@@ -328,6 +328,13 @@ BOOST_AUTO_TEST_CASE( getLoggerForType )
BOOST_AUTO_TEST_SUITE_END();
+BOOST_AUTO_TEST_CASE( syslog )
+{
+ IceTray::Logging::LogWriterPtr lwp =
+ IceTray::Logging::LogWriterFactory::createNew("SyslogLogWriter", nullptr);
+ lwp->message(LogLevel::DEBUG, testDomain, "some message", {});
+}
+
BOOST_AUTO_TEST_CASE( console )
{
IceTray::Logging::LogWriterPtr lwp =