diff options
author | Alexander Chemeris <Alexander.Chemeris@gmail.com> | 2017-03-17 18:35:48 -0700 |
---|---|---|
committer | Alexander Chemeris <Alexander.Chemeris@gmail.com> | 2017-03-20 17:32:04 +0000 |
commit | 4793f4679ba8720c55165d74b317627e0d60308e (patch) | |
tree | f39a222df871381ab4259f65c26f1cd468412557 /CommonLibs/Logger.cpp | |
parent | 802b86502dbcffe260b0424477987695872e676f (diff) |
CommonLibs: Remove unused files.
Change-Id: I2bfb45a1c7d01785bdb30204dba38c683a4288a9
Diffstat (limited to 'CommonLibs/Logger.cpp')
-rw-r--r-- | CommonLibs/Logger.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/CommonLibs/Logger.cpp b/CommonLibs/Logger.cpp index 82391cc..4e4dbbc 100644 --- a/CommonLibs/Logger.cpp +++ b/CommonLibs/Logger.cpp @@ -30,6 +30,7 @@ #include <fstream> #include <string> #include <stdarg.h> +#include <sys/time.h> // For gettimeofday #include "Configuration.h" #include "Logger.h" @@ -111,6 +112,31 @@ int lookupLevel(const string& key) return level; } +static std::string format(const char *fmt, ...) +{ + va_list ap; + char buf[300]; + va_start(ap,fmt); + int n = vsnprintf(buf,300,fmt,ap); + va_end(ap); + if (n >= (300-4)) { strcpy(&buf[(300-4)],"..."); } + return std::string(buf); +} + +const std::string timestr() +{ + struct timeval tv; + struct tm tm; + gettimeofday(&tv,NULL); + localtime_r(&tv.tv_sec,&tm); + unsigned tenths = tv.tv_usec / 100000; // Rounding down is ok. + return format(" %02d:%02d:%02d.%1d",tm.tm_hour,tm.tm_min,tm.tm_sec,tenths); +} + +std::ostream& operator<<(std::ostream& os, std::ostringstream& ss) +{ + return os << ss.str(); +} int getLoggingLevel(const char* filename) { |