| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- //
- // common.cxx
- // logging
- //
- // Created by Sam Jaffe on 4/1/19.
- //
- #include "common.h"
- #include <cassert>
- #include <ctime>
- #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));
- }
- }
|