remove timeval, it is not used. Fix issure with _WIN32. Untested.

JSON-105
Roker 5 years ago
parent 8f180cb41b
commit 65f1bcbd37

@ -213,22 +213,18 @@ void Logger::start(const std::string& program_name, const std::string& filename)
std::string Logger::gmtime(time_t t)
{
char buf[24]; // long enough to hold YYYYY-MM-DD.hh:mm:ss" (y10k-safe!)
std::tm T;
gmtime_r(&t, &T); // TODO: GNU extension also in std:: ?
std::snprintf(buf, sizeof(buf)-1, "%04d-%02d-%02d.%02d:%02d:%02d",
T.tm_year+1900, T.tm_mon+1, T.tm_mday, T.tm_hour, T.tm_min, T.tm_sec );
return buf;
}
// Win32 does not have gmtime_r(), but its gmtime() returns ptr to thread-local struct tm. :-)
#ifdef _WIN32
std::tm* T = gmtime(&t);
#else
std::tm myT;
gmtime_r(&t, &myT); // TODO: GNU extension, conform to POSIX.1; works on Linux and MacOS.
std::tm* T = &myT;
#endif
std::string Logger::gmtime(timeval t)
{
char buf[31]; // long enough to hold YYYYY-MM-DD.hh:mm:ss.uuuuuu
std::tm T;
gmtime_r(&t.tv_sec, &T); // TODO: GNU extension also in std:: ?
std::snprintf(buf, sizeof(buf)-1, "%04d-%02d-%02d.%02d:%02d:%02d.%06lu",
T.tm_year+1900, T.tm_mon+1, T.tm_mday, T.tm_hour, T.tm_min, T.tm_sec, (long unsigned)t.tv_usec);
std::snprintf(buf, sizeof(buf)-1, "%04d-%02d-%02d.%02d:%02d:%02d",
T->tm_year+1900, T->tm_mon+1, T->tm_mday, T->tm_hour, T->tm_min, T->tm_sec );
return buf;
}

@ -4,8 +4,6 @@
#include <cstdio>
#include <string>
#include <cerrno>
#include <sys/time.h>
#ifdef DEBUG_ENABLED
#define DEBUG_OUT( LL , ... ) LL.debug( __VA_ARGS__ )
@ -59,9 +57,6 @@ public:
// returns a string in YYYY-MM-DD.hh:mm:ss format of the given time_t t
static std::string gmtime(time_t t);
// returns a string in YYYY-MM-DD.hh:mm:ss.uuuuuu format (u=microseconds) of the given timval
static std::string gmtime(timeval t);
void emergency(const char* format, ...) PRINTF;
void emergency(const std::string& line);

Loading…
Cancel
Save