From 561aae3b03cec35e14e529f0006155ee3db07df5 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 24 Jan 2017 18:27:05 +0100 Subject: Initialise syslog earlier, don't leak the syslog backend --- src/ConfigParser.cpp | 6 ------ src/DabMux.cpp | 7 ++++++- src/Log.cpp | 13 ++++++------- src/Log.h | 17 ++++++++--------- 4 files changed, 20 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index 7219663..f0ab13c 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -218,12 +218,6 @@ void parse_ptree( ensemble->mode = 0; } - /* Enable Logging to syslog conditionally */ - if (pt_general.get("syslog", false)) { - etiLog.register_backend(new LogToSyslog()); // TODO don't leak the LogToSyslog backend - } - - /******************** READ ENSEMBLE PARAMETERS *************/ ptree pt_ensemble = pt.get_child("ensemble"); diff --git a/src/DabMux.cpp b/src/DabMux.cpp index 069af48..3870df5 100644 --- a/src/DabMux.cpp +++ b/src/DabMux.cpp @@ -3,7 +3,7 @@ 2011, 2012 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C) 2016 + Copyright (C) 2017 Matthias P. Braendli, matthias.braendli@mpb.li http://www.opendigitalradio.org @@ -235,6 +235,11 @@ int main(int argc, char *argv[]) throw MuxInitException("No configuration file specified"); } + /* Enable Logging to syslog conditionally */ + if (pt.get("general.syslog", false)) { + etiLog.register_backend(std::make_shared()); + } + int mgmtserverport = pt.get("general.managementport", pt.get("general.statsserverport", 0) ); diff --git a/src/Log.cpp b/src/Log.cpp index 35f3fae..9a58805 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -3,7 +3,10 @@ Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C), 2014, Matthias P. Braendli, matthias.braendli@mpb.li + Copyright (C) 2017 + Matthias P. Braendli, matthias.braendli@mpb.li + + http://www.opendigitalradio.org */ /* This file is part of ODR-DabMux. @@ -22,17 +25,13 @@ along with ODR-DabMux. If not, see . */ -#include -#include - #include "Log.h" Logger etiLog; - -void Logger::register_backend(LogBackend* backend) { +void Logger::register_backend(std::shared_ptr backend) +{ backends.push_back(backend); - //log(info, "Registered new logger " + backend->get_name()); } diff --git a/src/Log.h b/src/Log.h index e14ca37..91c9dc3 100644 --- a/src/Log.h +++ b/src/Log.h @@ -3,7 +3,10 @@ Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C), 2014, Matthias P. Braendli, matthias.braendli@mpb.li + Copyright (C) 2017 + Matthias P. Braendli, matthias.braendli@mpb.li + + http://www.opendigitalradio.org */ /* This file is part of ODR-DabMux. @@ -22,8 +25,7 @@ along with ODR-DabMux. If not, see . */ -#ifndef _LOG_H -#define _LOG_H +#pragma once #ifdef HAVE_CONFIG_H # include "config.h" @@ -40,6 +42,7 @@ #include #include #include +#include #define SYSLOG_IDENT "ODR-DabMux" #define SYSLOG_FACILITY LOG_LOCAL0 @@ -131,9 +134,7 @@ class LogLine; class Logger { public: - Logger() {} - - void register_backend(LogBackend* backend); + void register_backend(std::shared_ptr backend); /* Log the message to all backends */ void log(log_level_t level, const char* fmt, ...); @@ -145,7 +146,7 @@ class Logger { LogLine level(log_level_t level); private: - std::list backends; + std::list > backends; std::mutex m_cerr_mutex; }; @@ -186,5 +187,3 @@ class LogLine { }; -#endif - -- cgit v1.2.3