Files
spark/src/lib/logging/Common.h
T

50 lines
1.1 KiB
C++

#pragma once
#include "lib/utils/windows_wrapper.h"
#include <array>
#include <limits>
#include <stdint.h>
#include <string>
#include <time.h>
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;
}
} // namespace log
} // namespace bts