libcruft-util/cruft/util/log/packet.hpp

58 lines
1.2 KiB
C++
Raw Permalink Normal View History

#pragma once
#include "level.hpp"
2021-04-14 10:23:33 +10:00
#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 ...ArgsT>
constexpr packet (
level_t _level,
fmt::format_string<ArgsT...> &&_format,
ArgsT &&..._args
) : packet (
_level,
2021-04-14 10:23:33 +10:00
fmt::format (
std::forward<fmt::format_string<ArgsT...>> (_format),
2021-04-14 10:23:33 +10:00
std::forward<ArgsT> (_args)...
)
)
{ ; }
level_t level;
std::string message;
clock::time_point timestamp;
};
}