// // common.cxx // logging // // Created by Sam Jaffe on 4/1/19. // #include "common.h" #include #include #define X(l) \ case logging::L##l: \ return #l; const char* logging::level_header(log_level l) { assert(l != logging::LNONE); switch (l) { X(FATAL) X(CRITICAL) X(ERROR) X(WARNING) X(INFO) X(DEBUG) X(TRACE) X(NONE) } } #undef X timeval logging::now() { struct timeval tv; gettimeofday( &tv, nullptr ); return tv; } std::string logging::timestamp() { time_t round = std::time(NULL); char buf[32]; std::strftime(buf, sizeof(buf), "%Y%m%dT%H%M%S", std::localtime(&round)); return buf; } namespace logging { std::ostream & operator<<(std::ostream & os, log_level l) { return os << std::string(level_header(l)); } }