57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "level.hpp"
|
|
|
|
#include <fmt/ostream.h>
|
|
|
|
#include <chrono>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
namespace cruft::log {
|
|
struct packet {
|
|
using clock = std::chrono::high_resolution_clock;
|
|
|
|
packet (level_t _level, std::string _message)
|
|
: level (_level)
|
|
, message (std::move (_message))
|
|
, timestamp (clock::now ())
|
|
{ ; }
|
|
|
|
|
|
template <typename ...ArgsT>
|
|
packet (
|
|
level_t _level,
|
|
std::string_view _format,
|
|
ArgsT &&..._args
|
|
) : packet (
|
|
_level,
|
|
fmt::vformat (
|
|
_format,
|
|
fmt::make_format_args(
|
|
std::forward<ArgsT> (_args)...
|
|
)
|
|
)
|
|
)
|
|
{ ; }
|
|
|
|
template <typename FormatT, typename ...ArgsT>
|
|
packet (
|
|
level_t _level,
|
|
FormatT _format,
|
|
ArgsT &&..._args
|
|
) : packet (
|
|
_level,
|
|
fmt::format (
|
|
std::forward<FormatT> (_format),
|
|
std::forward<ArgsT> (_args)...
|
|
)
|
|
)
|
|
{ ; }
|
|
|
|
level_t level;
|
|
std::string message;
|
|
clock::time_point timestamp;
|
|
};
|
|
} |