Initial commit

This commit is contained in:
2020-02-06 08:54:57 +01:00
commit 7beeaadce6
8 changed files with 150 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
*.o.*
*.d.*
*.a.*
.*.swp
.AppleDouble
lib
fixPermissions.sh
+79
View File
@@ -0,0 +1,79 @@
#include <iostream>
#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
#include "Logging.h"
namespace Logging {
void OpenLog()
{
openlog(NULL, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_USER);
}
void CloseLog()
{
closelog();
}
void SetLogMask(Severity::type severity)
{
int level = static_cast<int>(severity);
setlogmask(LOG_UPTO(level));
switch (level)
{
case LOG_EMERG:
Syslog(LOG_EMERG, "LogMask set to LOG_EMERG\n");
break;
case LOG_ALERT:
Syslog(LOG_ALERT, "LogMask set to LOG_ALERT\n");
break;
case LOG_CRIT:
Syslog(LOG_CRIT, "LogMask set to LOG_CRIT\n");
break;
case LOG_ERR:
Syslog(LOG_ERR, "LogMask set to LOG_ERR\n");
break;
case LOG_WARNING:
Syslog(LOG_WARNING, "LogMask set to LOG_WARNING\n");
break;
case LOG_NOTICE:
Syslog(LOG_NOTICE, "LogMask set to LOG_NOTICE\n");
break;
case LOG_INFO:
Syslog(LOG_NOTICE, "LogMask set to LOG_INFO\n");
break;
case LOG_DEBUG:
Syslog(LOG_NOTICE, "LogMask set to LOG_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;
Syslog(static_cast<int>(severity), "%s", message.c_str());
}
void Syslog(int level, const char *format, ...)
{
va_list args;
va_start(args, format);
vsyslog(level, format, args);
if (level == LOG_DEBUG)
printf(" ");
vprintf(format, args);
va_end(args);
}
} // namespace Logging
+1
View File
@@ -0,0 +1 @@
../Makefile
Symlink
+1
View File
@@ -0,0 +1 @@
Makefiles/Makefile
+7
View File
@@ -0,0 +1,7 @@
#
# Makefile.conf
#
CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include
DEBUGDIR := .debug
+12
View File
@@ -0,0 +1,12 @@
#
# Makefile.target
#
Logging.a.$(ARCH) : $(OBJECTS)
$(call build_target_library_arch,$@,$^)
Logging.a:
$(call build_target,$@)
.DEFAULT_GOAL := Logging.a
TARGETS += Logging.a
Symlink
+1
View File
@@ -0,0 +1 @@
../../Makefiles
+42
View File
@@ -0,0 +1,42 @@
#ifndef LOGGER_H
#define LOGGER_H
#include <string>
namespace Logging {
#define LOG_EMERG 0
#define LOG_ALERT 1
#define LOG_CRIT 2
#define LOG_ERR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
struct Severity
{
public:
enum type
{
Emergency = LOG_EMERG,
Alert = LOG_ALERT,
Critical = LOG_CRIT,
Error = LOG_ERR,
Warning = LOG_WARNING,
Notice = LOG_NOTICE,
Info = LOG_INFO,
Debug = LOG_DEBUG
};
};
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
#endif // LOGGING_LOGGER_H