9 static const char rcsid[] __attribute__((used)) =
"$Id: LogFormat.cpp 1664 2016-04-04 03:57:40Z sella $";
11 #include "LogFormat.h"
13 #include "../Exception.h"
21 using namespace sella::util;
23 const std::string LogFormat::DefaultStampFormat(DEFAULTSTAMPFORMAT);
25 LogFormat::LogFormat(
const std::string &stamp,
bool micro)
throw () :
30 std::string LogFormat::format(
const struct timeval &stamp)
throw () {
31 char buffer[512] = { 0 };
32 char micro[64] = { 0 };
35 localtime_r(&(stamp.tv_sec), &time);
38 size_t tlen = strftime(buffer,
sizeof(buffer) -
sizeof(micro), this->stamp.c_str(), &time);
39 size_t mlen = snprintf(micro,
sizeof(micro),
".%06lu", stamp.tv_usec);
41 strncpy(buffer + tlen, micro, mlen);
43 strftime(buffer,
sizeof(buffer), this->stamp.c_str(), &time);
46 return std::string(buffer);