diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-04-22 21:54:56 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-04-22 21:54:56 +0200 |
commit | c8a331c8000004ff68422e034332890c002b04c3 (patch) | |
tree | a4d83a932753d8134cb36d3f7e486a36f89ee9e4 /src/Log.h | |
parent | 96635c032658cc3d45007c02a0701a5961a40c39 (diff) | |
download | dabmod-c8a331c8000004ff68422e034332890c002b04c3.tar.gz dabmod-c8a331c8000004ff68422e034332890c002b04c3.tar.bz2 dabmod-c8a331c8000004ff68422e034332890c002b04c3.zip |
Take some Log improvements from ODR-DabMux
Diffstat (limited to 'src/Log.h')
-rw-r--r-- | src/Log.h | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -3,10 +3,10 @@ Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C) 2016 + Copyright (C) 2018 Matthias P. Braendli, matthias.braendli@mpb.li - http://opendigitalradio.org + http://www.opendigitalradio.org */ /* This file is part of ODR-DabMod. @@ -42,6 +42,7 @@ #include <string> #include <map> #include <mutex> +#include <memory> #include <thread> #include "ThreadsafeQueue.h" @@ -56,6 +57,7 @@ static const std::string levels_as_str[] = /** Abstract class all backends must inherit from */ class LogBackend { public: + virtual ~LogBackend() {}; virtual void log(log_level_t level, const std::string& message) = 0; virtual std::string get_name() const = 0; }; @@ -67,7 +69,7 @@ class LogToSyslog : public LogBackend { openlog(SYSLOG_IDENT, LOG_PID, SYSLOG_FACILITY); } - ~LogToSyslog() { + virtual ~LogToSyslog() { closelog(); } @@ -117,9 +119,9 @@ class LogTracer : public LogBackend { class LogLine; struct log_message_t { - log_message_t(log_level_t _level, const std::string& _message) : + log_message_t(log_level_t _level, std::string&& _message) : level(_level), - message(_message) {} + message(move(_message)) {} log_message_t() : level(debug), @@ -142,12 +144,12 @@ class Logger { m_io_thread.join(); } - void register_backend(LogBackend* backend); + void register_backend(std::shared_ptr<LogBackend> backend); /* Log the message to all backends */ void log(log_level_t level, const char* fmt, ...); - void logstr(log_level_t level, std::string message); + void logstr(log_level_t level, std::string&& message); /* All logging IO is done in another thread */ void io_process(void); @@ -157,7 +159,7 @@ class Logger { LogLine level(log_level_t level); private: - std::list<LogBackend*> backends; + std::list<std::shared_ptr<LogBackend> > backends; ThreadsafeQueue<log_message_t> m_message_queue; std::thread m_io_thread; |