summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-02-28 18:42:10 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-02-28 18:53:46 +0100
commit0818f2dec28732cd55071474c27732cc3196d772 (patch)
treee2acfdb538f21f54319ef0b0a01309babcaf9e51 /src
parent3ab4c81e9cdcdc42118672fb0d38690db8f2478f (diff)
downloaddabmod-0818f2dec28732cd55071474c27732cc3196d772.tar.gz
dabmod-0818f2dec28732cd55071474c27732cc3196d772.tar.bz2
dabmod-0818f2dec28732cd55071474c27732cc3196d772.zip
Protect cerr by mutex in Log, and minor things
Diffstat (limited to 'src')
-rw-r--r--src/Log.cpp5
-rw-r--r--src/Log.h15
2 files changed, 14 insertions, 6 deletions
diff --git a/src/Log.cpp b/src/Log.cpp
index 7db1d44..6bbc7a9 100644
--- a/src/Log.cpp
+++ b/src/Log.cpp
@@ -72,7 +72,10 @@ void Logger::logstr(log_level_t level, std::string message)
backend->log(level, message);
}
- std::cerr << levels_as_str[level] << " " << message << std::endl;
+ {
+ std::lock_guard<std::mutex> guard(m_cerr_mutex);
+ std::cerr << levels_as_str[level] << " " << message << std::endl;
+ }
}
diff --git a/src/Log.h b/src/Log.h
index 01afa75..f3b4409 100644
--- a/src/Log.h
+++ b/src/Log.h
@@ -39,13 +39,14 @@
#include <stdexcept>
#include <string>
#include <map>
+#include <mutex>
#define SYSLOG_IDENT "ODR-DabMod"
#define SYSLOG_FACILITY LOG_LOCAL0
enum log_level_t {debug = 0, info, warn, error, alert, emerg};
-const std::string levels_as_str[] =
+static const std::string levels_as_str[] =
{ " ", " ", "WARN ", "ERROR", "ALERT", "EMERG"} ;
/** Abstract class all backends must inherit from */
@@ -72,17 +73,19 @@ class LogToSyslog : public LogBackend {
int syslog_level = LOG_EMERG;
switch (level) {
case debug: syslog_level = LOG_DEBUG; break;
- case alert: syslog_level = LOG_ALERT; break;
case info: syslog_level = LOG_INFO; break;
+ /* we don't have the notice level */
case warn: syslog_level = LOG_WARNING; break;
case error: syslog_level = LOG_ERR; break;
+ default: syslog_level = LOG_CRIT; break;
+ case alert: syslog_level = LOG_ALERT; break;
case emerg: syslog_level = LOG_EMERG; break;
}
syslog(syslog_level, SYSLOG_IDENT " %s", message.c_str());
}
- std::string get_name() { return name; };
+ std::string get_name() { return name; }
private:
std::string name;
@@ -117,7 +120,7 @@ class LogToFile : public LogBackend {
fflush(log_file);
}
- std::string get_name() { return name; };
+ std::string get_name() { return name; }
private:
std::string name;
@@ -128,7 +131,7 @@ class LogLine;
class Logger {
public:
- Logger() {};
+ Logger() {}
void register_backend(LogBackend* backend);
@@ -143,6 +146,8 @@ class Logger {
private:
std::list<LogBackend*> backends;
+
+ std::mutex m_cerr_mutex;
};
extern Logger etiLog;