diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-06-17 11:19:29 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-06-17 11:19:29 +0200 |
commit | bab9d654f028a214e6f3abe8ade1c1da002d25ff (patch) | |
tree | 12580eddcaf217a5a86bb5b1a5efd1443bdef153 /src/Log.h | |
parent | 9f09681adda2b76ab08c96548bac2384ed8eae4d (diff) | |
download | dabmod-bab9d654f028a214e6f3abe8ade1c1da002d25ff.tar.gz dabmod-bab9d654f028a214e6f3abe8ade1c1da002d25ff.tar.bz2 dabmod-bab9d654f028a214e6f3abe8ade1c1da002d25ff.zip |
Add TRACE support for timing analysis
Diffstat (limited to 'src/Log.h')
-rw-r--r-- | src/Log.h | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -44,10 +44,10 @@ #define SYSLOG_IDENT "ODR-DabMod" #define SYSLOG_FACILITY LOG_LOCAL0 -enum log_level_t {debug = 0, info, warn, error, alert, emerg}; +enum log_level_t {debug = 0, info, warn, error, alert, emerg, trace}; static const std::string levels_as_str[] = - { " ", " ", "WARN ", "ERROR", "ALERT", "EMERG"} ; + { " ", " ", "WARN ", "ERROR", "ALERT", "EMERG", "TRACE"} ; /** Abstract class all backends must inherit from */ class LogBackend { @@ -72,6 +72,7 @@ class LogToSyslog : public LogBackend { int syslog_level = LOG_EMERG; switch (level) { + case trace: break; // Do not handle TRACE in syslog case debug: syslog_level = LOG_DEBUG; break; case info: syslog_level = LOG_INFO; break; /* we don't have the notice level */ @@ -89,6 +90,9 @@ class LogToSyslog : public LogBackend { private: std::string name; + + LogToSyslog(const LogToSyslog& other) = delete; + const LogToSyslog& operator=(const LogToSyslog& other) = delete; }; class LogToFile : public LogBackend { @@ -109,22 +113,37 @@ class LogToFile : public LogBackend { } } - void log(log_level_t level, std::string message) { + void log(log_level_t level, std::string message); + + std::string get_name() { return name; } - const char* log_level_text[] = - {"DEBUG", "INFO", "WARN", "ERROR", "ALERT", "EMERG"}; + private: + std::string name; + FILE* log_file; - // fprintf is thread-safe - fprintf(log_file, SYSLOG_IDENT ": %s: %s\n", - log_level_text[(size_t)level], message.c_str()); - fflush(log_file); + LogToFile(const LogToFile& other) = delete; + const LogToFile& operator=(const LogToFile& other) = delete; +}; + +class LogTracer : public LogBackend { + public: + LogTracer(const std::string& filename); + + ~LogTracer() { + if (m_trace_file != NULL) { + fclose(m_trace_file); + } } + void log(log_level_t level, std::string message); std::string get_name() { return name; } - private: std::string name; - FILE* log_file; + uint64_t m_trace_micros_startup; + FILE* m_trace_file; + + LogTracer(const LogTracer& other) = delete; + const LogTracer& operator=(const LogTracer& other) = delete; }; class LogLine; |