diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-01-12 21:45:54 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-01-12 21:45:54 +0100 |
commit | e9c4e1762c3b7531ffe82dc26c67919ee38bfc3a (patch) | |
tree | ab1d49f6bd9538a2dba69dda98a00fcac5ab8953 /src/Log.cpp | |
parent | 1ee5bb5d436067d979fd95f98ed36addcd2efaed (diff) | |
download | dabmux-e9c4e1762c3b7531ffe82dc26c67919ee38bfc3a.tar.gz dabmux-e9c4e1762c3b7531ffe82dc26c67919ee38bfc3a.tar.bz2 dabmux-e9c4e1762c3b7531ffe82dc26c67919ee38bfc3a.zip |
update Log.{h,cpp}
Diffstat (limited to 'src/Log.cpp')
-rw-r--r-- | src/Log.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/Log.cpp b/src/Log.cpp index 7dd9d18..64e7ceb 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -23,9 +23,9 @@ */ #include <list> +#include <stdarg.h> #include "Log.h" -#include "porting.h" Logger etiLog; @@ -36,7 +36,31 @@ void Logger::register_backend(LogBackend* backend) { } -void Logger::log(log_level_t level, std::string message) { +void Logger::log(log_level_t level, const char* fmt, ...) +{ + int size = 100; + std::string str; + va_list ap; + while (1) { + str.resize(size); + va_start(ap, fmt); + int n = vsnprintf((char *)str.c_str(), size, fmt, ap); + va_end(ap); + if (n > -1 && n < size) { + str.resize(n); + break; + } + if (n > -1) + size = n + 1; + else + size *= 2; + } + + logstr(level, str); +} + +void Logger::logstr(log_level_t level, const std::string message) +{ for (std::list<LogBackend*>::iterator it = backends.begin(); it != backends.end(); it++) { |