From 02c49d986b9bbf49a4770d5e40decab0aa0aeb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Me=C3=9Fmer?= Date: Sat, 17 Oct 2015 03:27:49 +0200 Subject: [PATCH] daemonize() redirects logger to syslog --- daemon/daemonize.cpp | 5 ++++- daemon/daemonize.h | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/daemon/daemonize.cpp b/daemon/daemonize.cpp index 4e72c480..cc823249 100644 --- a/daemon/daemonize.cpp +++ b/daemon/daemonize.cpp @@ -18,7 +18,7 @@ namespace cpputils { //TODO Test daemonize() - void daemonize() { + void daemonize(const std::string &daemonName) { pid_t pid = fork(); if (pid < 0) { exit(EXIT_FAILURE); @@ -44,6 +44,9 @@ namespace cpputils { exit(EXIT_FAILURE); } + // Setup logging to syslog. + cpputils::logging::setLogger(spdlog::syslog_logger(daemonName, daemonName, LOG_PID)); + // Close out the standard file descriptors. The daemon can't use them anyhow. close(STDIN_FILENO); close(STDOUT_FILENO); diff --git a/daemon/daemonize.h b/daemon/daemonize.h index 5e7b142d..9fd9a351 100644 --- a/daemon/daemonize.h +++ b/daemon/daemonize.h @@ -2,8 +2,10 @@ #ifndef MESSMER_CPPUTILS_DAEMON_DAEMONIZE_H #define MESSMER_CPPUTILS_DAEMON_DAEMONIZE_H +#include + namespace cpputils { - void daemonize(); + void daemonize(const std::string &daemonName); } #endif