From 223d70be498dc240a92bb8961bfd5d99cebbcf1d Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 24 Oct 2016 20:29:24 +0200 Subject: Minor improvements in log --- src/Log.h | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/Log.h') diff --git a/src/Log.h b/src/Log.h index d6cd651..0714835 100644 --- a/src/Log.h +++ b/src/Log.h @@ -25,8 +25,7 @@ along with ODR-DabMod. If not, see . */ -#ifndef _LOG_H -#define _LOG_H +#pragma once #ifdef HAVE_CONFIG_H # include "config.h" @@ -57,15 +56,14 @@ static const std::string levels_as_str[] = /** Abstract class all backends must inherit from */ class LogBackend { public: - virtual void log(log_level_t level, std::string message) = 0; + virtual void log(log_level_t level, const std::string& message) = 0; virtual std::string get_name() = 0; }; /** A Logging backend for Syslog */ class LogToSyslog : public LogBackend { public: - LogToSyslog() { - name = "SYSLOG"; + LogToSyslog() : name("SYSLOG") { openlog(SYSLOG_IDENT, LOG_PID, SYSLOG_FACILITY); } @@ -73,12 +71,12 @@ class LogToSyslog : public LogBackend { closelog(); } - void log(log_level_t level, std::string message); + void log(log_level_t level, const std::string& message); std::string get_name() { return name; } private: - std::string name; + const std::string name; LogToSyslog(const LogToSyslog& other) = delete; const LogToSyslog& operator=(const LogToSyslog& other) = delete; @@ -86,9 +84,7 @@ class LogToSyslog : public LogBackend { class LogToFile : public LogBackend { public: - LogToFile(std::string filename) { - name = "FILE"; - + LogToFile(const std::string& filename) : name("FILE") { log_file = fopen(filename.c_str(), "a"); if (log_file == NULL) { fprintf(stderr, "Cannot open log file !"); @@ -102,12 +98,12 @@ class LogToFile : public LogBackend { } } - void log(log_level_t level, std::string message); + void log(log_level_t level, const std::string& message); std::string get_name() { return name; } private: - std::string name; + const std::string name; FILE* log_file; LogToFile(const LogToFile& other) = delete; @@ -124,7 +120,7 @@ class LogTracer : public LogBackend { } } - void log(log_level_t level, std::string message); + void log(log_level_t level, const std::string& message); std::string get_name() { return name; } private: std::string name; @@ -220,6 +216,3 @@ class LogLine { Logger* logger_; }; - -#endif - -- cgit v1.2.3