diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-10-24 20:29:24 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-10-24 20:29:24 +0200 |
commit | 223d70be498dc240a92bb8961bfd5d99cebbcf1d (patch) | |
tree | 934567377d5db3caee7263d7ffc4fc243285c399 /src | |
parent | 5297666e1352be672c7dc6fe3af44950a52428da (diff) | |
download | dabmod-223d70be498dc240a92bb8961bfd5d99cebbcf1d.tar.gz dabmod-223d70be498dc240a92bb8961bfd5d99cebbcf1d.tar.bz2 dabmod-223d70be498dc240a92bb8961bfd5d99cebbcf1d.zip |
Minor improvements in log
Diffstat (limited to 'src')
-rw-r--r-- | src/Log.cpp | 6 | ||||
-rw-r--r-- | src/Log.h | 25 |
2 files changed, 12 insertions, 19 deletions
diff --git a/src/Log.cpp b/src/Log.cpp index 155fc00..77687fc 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -114,7 +114,7 @@ LogLine Logger::level(log_level_t level) return LogLine(this, level); } -void LogToFile::log(log_level_t level, std::string message) +void LogToFile::log(log_level_t level, const std::string& message) { if (level != log_level_t::trace) { const char* log_level_text[] = { @@ -127,7 +127,7 @@ void LogToFile::log(log_level_t level, std::string message) } } -void LogToSyslog::log(log_level_t level, std::string message) +void LogToSyslog::log(log_level_t level, const std::string& message) { if (level != log_level_t::trace) { int syslog_level = LOG_EMERG; @@ -165,7 +165,7 @@ LogTracer::LogTracer(const string& trace_filename) fprintf(m_trace_file, "0,TRACER,startup at %ld\n", m_trace_micros_startup); } -void LogTracer::log(log_level_t level, std::string message) +void LogTracer::log(log_level_t level, const std::string& message) { if (level == log_level_t::trace) { const auto now = chrono::steady_clock::now().time_since_epoch(); @@ -25,8 +25,7 @@ along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>. */ -#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 - |