Files
spark/src/lib/logging/Common.h
T
Pedro Pinto 07a3f99f78 Added a log pretty-printer and precise time stamps to log msgs.
We now get a total order for log messages that makes sense and also
the possiblity of measuring the time between any log messages
precisely. This can be used to provide latency logs for the spreader
or any other critical part of the system.
2017-12-29 15:58:53 -05:00

49 lines
1.1 KiB
C++

#pragma once
#include "lib/utils/windows_wrapper.h"
#include <stdint.h>
#include <array>
#include <limits>
#include <string>
namespace bts {
namespace log {
struct Level {
using Rep = uint8_t;
constexpr static auto Max = std::numeric_limits<Rep>::max();
Rep ordinal;
bool operator<(const Level &rhs) const {return ordinal < rhs.ordinal;}
};
struct Subsystem {
using Rep = uint8_t;
constexpr static auto Max = std::numeric_limits<Rep>::max();
Rep ordinal;
bool operator<(const Subsystem &rhs) const {return ordinal < rhs.ordinal;}
};
using ArgBuffer = std::array<uint8_t,156>;
using MsgFormatter = std::string(*) (ArgBuffer const&,const char*);
using Filter = std::array<Level,Subsystem::Max+1>;
inline uint64_t log_ts() {
uint64_t result;
#ifdef _WIN32
LARGE_INTEGER qpcnt;
QueryPerformanceCounter(&qpcnt);
result = qpcnt.QuadPart;
#else
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC, &ts );
result =
static_cast<int64_t>(1000000000UL)*
static_cast<int64_t>(ts.tv_sec) +
static_cast<int64_t>(ts.tv_nsec);
#endif
return result;
}
}}