log/syslog.cpp
#include <syslog.h>
#include <toast/log.hpp>
using namespace toast::log;
struct to_syslog {
typedef char char_type;
static void message(char_type const *message, int severity)
{
switch(severity) {
case DEFAULT: severity = LOG_ERR; break;
case FATAL: severity = LOG_EMERG; break;
case ALERT: severity = LOG_ALERT; break;
case CRITICAL: severity = LOG_CRIT; break;
case ERROR: severity = LOG_ERR; break;
case WARNING: severity = LOG_WARNING; break;
case NOTICE: severity = LOG_NOTICE; break;
case INFO: severity = LOG_INFO; break;
case DEBUG: severity = LOG_DEBUG; break;
default: severity = LOG_ERR; break;
}
syslog(severity, "%s", message);
}
};
typedef logger<always_output, to_syslog> Log;
void system_log_example()
{
openlog("toast::log system logging example", LOG_PID, LOG_USER);
Log s;
s.message("Let's annoy the sysadmins with toast::log!", INFO);
s.message("Let's annoy the sysadmins with toast::log!", INFO);
}