Remove Syslog command, fix double newline issue

This commit is contained in:
2020-03-07 19:36:06 +01:00
parent ac55e67c99
commit 04ccb8eed5
5 changed files with 22 additions and 30 deletions
-2
View File
@@ -4,5 +4,3 @@
.*.swp
.AppleDouble
lib
Libraries
fixPermissions.sh
+1
View File
@@ -0,0 +1 @@
../../Utilities
+20 -25
View File
@@ -1,4 +1,5 @@
#include "Logging.h"
#include <StringAlgorithm.h>
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
@@ -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<int>(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<int>(severity), "%s", message.c_str());
}
} // namespace Logging
+1 -2
View File
@@ -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
-1
View File
@@ -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