Files
spark/src/lib/logging/LogRec.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

44 lines
904 B
C++

#pragma once
#include "lib/utils/warn_ctrl.h"
#include "Common.h"
#include "MsgPacking.h"
namespace bts {
namespace log {
using ArgUnpacker = std::string (*) (ArgBuffer const&b, const char*msg_template);
GCC_DIAG_OFF("-Weffc++")
struct LogRec {
uint64_t ts;
const char *file;
const char *msg_template;
ArgUnpacker unpacker;
uint16_t line;
Level level;
Subsystem subsystem;
ArgBuffer args;
template <typename... Args>
void pack_msg (const char *msg_t, Args&&... msg_args) {
msg_template = msg_t;
unpacker = unpack_msg_args<sizeof(ArgBuffer),typename std::remove_reference<Args>::type...>;
pack_msg_args(args,std::forward<Args>(msg_args)...);
}
std::string unpack_msg()
{
return unpacker(args,msg_template);
}
};
GCC_DIAG_RESTORE()
#ifndef WIN32
//static_assert(sizeof(LogRec) == 256, "LogRec should be 128 bytes");
#endif
}}