From 04ccb8eed5ddf657b5298673921292fdf8c2332c Mon Sep 17 00:00:00 2001 From: JDierkse Date: Sat, 7 Mar 2020 19:36:06 +0100 Subject: [PATCH] Remove Syslog command, fix double newline issue --- .gitignore | 2 -- Libraries/Utilities | 1 + Logging/Logging.cpp | 45 ++++++++++++++++++++------------------------- Makefile.conf | 3 +-- include/Logging.h | 1 - 5 files changed, 22 insertions(+), 30 deletions(-) create mode 120000 Libraries/Utilities diff --git a/.gitignore b/.gitignore index 5c150de..851ef09 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,3 @@ .*.swp .AppleDouble lib -Libraries -fixPermissions.sh diff --git a/Libraries/Utilities b/Libraries/Utilities new file mode 120000 index 0000000..4a6b454 --- /dev/null +++ b/Libraries/Utilities @@ -0,0 +1 @@ +../../Utilities \ No newline at end of file diff --git a/Logging/Logging.cpp b/Logging/Logging.cpp index 3df5ef9..2ce0860 100644 --- a/Logging/Logging.cpp +++ b/Logging/Logging.cpp @@ -1,4 +1,5 @@ #include "Logging.h" +#include #include #include #include @@ -9,7 +10,7 @@ namespace Logging { void OpenLog() { - openlog(NULL, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_USER); + openlog(NULL, LOG_NDELAY | LOG_PID, LOG_USER); } void CloseLog() @@ -25,55 +26,49 @@ void SetLogMask(Severity::type severity) switch (level) { case LOG_EMERG: - Syslog(LOG_EMERG, "LogMask set to LOG_EMERG\n"); + Log(Severity::Emergency, "LogMask set to Severity::Emergency\n"); break; case LOG_ALERT: - Syslog(LOG_ALERT, "LogMask set to LOG_ALERT\n"); + Log(Severity::Alert, "LogMask set to Severity::Alert\n"); break; case LOG_CRIT: - Syslog(LOG_CRIT, "LogMask set to LOG_CRIT\n"); + Log(Severity::Critical, "LogMask set to Severity::Critical\n"); break; case LOG_ERR: - Syslog(LOG_ERR, "LogMask set to LOG_ERR\n"); + Log(Severity::Error, "LogMask set to Severity::Error\n"); break; case LOG_WARNING: - Syslog(LOG_WARNING, "LogMask set to LOG_WARNING\n"); + Log(Severity::Warning, "LogMask set to Severity::Warning\n"); break; case LOG_NOTICE: - Syslog(LOG_NOTICE, "LogMask set to LOG_NOTICE\n"); + Log(Severity::Notice, "LogMask set to Severity::Notice\n"); break; case LOG_INFO: - Syslog(LOG_NOTICE, "LogMask set to LOG_INFO\n"); + Log(Severity::Notice, "LogMask set to Severity::Info\n"); break; case LOG_DEBUG: - Syslog(LOG_NOTICE, "LogMask set to LOG_DEBUG\n"); + Log(Severity::Notice, "LogMask set to Severity::Debug\n"); break; } } void Log(Severity::type severity, const std::string& message) { - if (severity > Severity::Error) - std::cout << message << std::endl; - else - std::cerr << message << std::endl; + bool error = (severity < Severity::Warning); + bool debug = (severity == Severity::Debug); + std::ostream& output = error? std::cerr: std::cout; - Syslog(static_cast(severity), "%s", message.c_str()); -} + bool newline = StringAlgorithm::ends_with(message, "\n"); -void Syslog(int level, const char *format, ...) -{ - va_list args; - va_start(args, format); + if (debug) + output << " "; - vsyslog(level, format, args); + output << message; - if (level == LOG_DEBUG) - printf(" "); + if (!newline) + output << std::endl; - vprintf(format, args); - - va_end(args); + syslog(static_cast(severity), "%s", message.c_str()); } } // namespace Logging diff --git a/Makefile.conf b/Makefile.conf index 98a5d49..d196d52 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -2,6 +2,5 @@ # Makefile.conf # -CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include +CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include -I$(ROOTPATH)/Libraries/Utilities/include DEBUGDIR := .debug - diff --git a/include/Logging.h b/include/Logging.h index 3fa664b..9ea3256 100644 --- a/include/Logging.h +++ b/include/Logging.h @@ -35,7 +35,6 @@ void OpenLog(); void CloseLog(); void SetLogMask(Severity::type severity); void Log(Severity::type severity, const std::string& message); -void Syslog(int level, const char *format, ...); } // namespace Logging