logman 0.1.0
Modern C++23 header-only logging manager wrapping spdlog with channels, listeners, and structured events
Loading...
Searching...
No Matches
log_event_json.hpp
Go to the documentation of this file.
1#pragma once
2
6
8
9#include <nlohmann/json.hpp>
10
11#include <chrono>
12
13namespace logman {
14
15inline void to_json(nlohmann::json& j, const LogEvent& e) {
16 const auto ts =
17 std::chrono::duration_cast<std::chrono::milliseconds>(e.timestamp.time_since_epoch())
18 .count();
19 j = nlohmann::json{
20 {"timestamp", ts},
21 {"level", e.level},
22 {"channel", e.channel},
23 {"message", e.message},
24 {"thread_id", e.thread_id},
25 };
26 if (e.process_id >= 0) {
27 j["process_id"] = e.process_id;
28 }
29 if (!e.file.empty()) {
30 j["file"] = e.file;
31 j["line"] = e.line;
32 j["function"] = e.function;
33 }
34}
35
36} // namespace logman
Plain-old-data structure describing one log record.