dfx
0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
Log.hpp
1
// SPDX-FileCopyrightText: 2025 Vincent Leroy
2
// SPDX-License-Identifier: MIT
3
//
4
// This file is part of dfx.
5
//
6
// Licensed under the MIT License. See the LICENSE file in the project root
7
// for full license information.
8
9
#pragma once
10
11
// Third-party includes
12
#include <spdlog/spdlog.h>
13
#include <spdlog/mdc.h>
14
15
namespace
dfx::Utils
16
{
17
static
constexpr
auto
defaultLogPattern =
"[%Y-%m-%d %H:%M:%S.%e] [%t] [%n] %^%L%$ - %v [%s:%#]"
;
18
static
constexpr
auto
noFileLogPattern =
"[%Y-%m-%d %H:%M:%S.%e] [%t] [%n] %^%L%$ - %v"
;
19
static
constexpr
auto
nodeLogPattern =
"[%Y-%m-%d %H:%M:%S.%e] [%t] [%&] %^%L%$ - %v [%s:%#]"
;
20
21
static
constexpr
auto
coreLoggerName =
"core"
;
22
static
constexpr
auto
runtimeLoggerName =
"runtime"
;
23
static
constexpr
auto
utilitiesLoggerName =
"utilities"
;
24
static
constexpr
auto
graphLoggerName =
"graph"
;
25
static
constexpr
auto
serverLoggerName =
"server"
;
26
static
constexpr
auto
nodeLoggerName =
"node"
;
27
static
constexpr
auto
pcapngLoggerName =
"pcapng"
;
28
static
constexpr
auto
fdwatchLoggerName =
"fdwatch"
;
29
static
constexpr
auto
clientLoggerName =
"client"
;
30
static
constexpr
auto
subprocessLoggerName =
"subprocess"
;
31
32
struct
ScopedMdc
33
{
34
public
:
35
ScopedMdc(std::string key, std::string
const
& value)
36
: _key { std::move(key) }
37
{ spdlog::mdc::put(_key, value); }
38
39
~ScopedMdc()
40
{ spdlog::mdc::remove(_key); }
41
42
private
:
43
std::string _key;
44
};
45
}
// !namespace dfx::Utils
46
47
#define DFX_LLOG(logger, level, msg, ...) \
48
do \
49
{ \
50
auto const _logger = logger; \
51
if (_logger != nullptr && _logger->should_log(level)) \
52
SPDLOG_LOGGER_CALL(_logger, level, msg __VA_OPT__(,) __VA_ARGS__); \
53
} while (false)
54
55
#define DFX_LLOG_TRACE(logger, msg, ...) DFX_LLOG(logger, spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
56
#define DFX_LLOG_DEBUG(logger, msg, ...) DFX_LLOG(logger, spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
57
#define DFX_LLOG_INFO(logger, msg, ...) DFX_LLOG(logger, spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
58
#define DFX_LLOG_WARN(logger, msg, ...) DFX_LLOG(logger, spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
59
#define DFX_LLOG_ERROR(logger, msg, ...) DFX_LLOG(logger, spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
60
#define DFX_LLOG_CRITICAL(logger, msg, ...) DFX_LLOG(logger, spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
61
62
#define DFX_DEFAULT_LOGGER() spdlog::default_logger()
63
#define DFX_LOG(level, msg, ...) DFX_LLOG(DFX_DEFAULT_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
64
#define DFX_LOG_TRACE(msg, ...) DFX_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
65
#define DFX_LOG_DEBUG(msg, ...) DFX_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
66
#define DFX_LOG_INFO(msg, ...) DFX_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
67
#define DFX_LOG_WARN(msg, ...) DFX_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
68
#define DFX_LOG_ERROR(msg, ...) DFX_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
69
#define DFX_LOG_CRITICAL(msg, ...) DFX_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
70
71
#define DFX_CORE_LOGGER() spdlog::get(::dfx::Utils::coreLoggerName)
72
#define DFX_CORE_LOG(level, msg, ...) DFX_LLOG(DFX_CORE_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
73
#define DFX_CORE_LOG_TRACE(msg, ...) DFX_CORE_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
74
#define DFX_CORE_LOG_DEBUG(msg, ...) DFX_CORE_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
75
#define DFX_CORE_LOG_INFO(msg, ...) DFX_CORE_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
76
#define DFX_CORE_LOG_WARN(msg, ...) DFX_CORE_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
77
#define DFX_CORE_LOG_ERROR(msg, ...) DFX_CORE_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
78
#define DFX_CORE_LOG_CRITICAL(msg, ...) DFX_CORE_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
79
80
#define DFX_RUNTIME_LOGGER() spdlog::get(::dfx::Utils::runtimeLoggerName)
81
#define DFX_RUNTIME_LOG(level, msg, ...) DFX_LLOG(DFX_RUNTIME_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
82
#define DFX_RUNTIME_LOG_TRACE(msg, ...) DFX_RUNTIME_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
83
#define DFX_RUNTIME_LOG_DEBUG(msg, ...) DFX_RUNTIME_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
84
#define DFX_RUNTIME_LOG_INFO(msg, ...) DFX_RUNTIME_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
85
#define DFX_RUNTIME_LOG_WARN(msg, ...) DFX_RUNTIME_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
86
#define DFX_RUNTIME_LOG_ERROR(msg, ...) DFX_RUNTIME_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
87
#define DFX_RUNTIME_LOG_CRITICAL(msg, ...) DFX_RUNTIME_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
88
89
#define DFX_UTILITIES_LOGGER() spdlog::get(::dfx::Utils::utilitiesLoggerName)
90
#define DFX_UTILITIES_LOG(level, msg, ...) DFX_LLOG(DFX_UTILITIES_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
91
#define DFX_UTILITIES_LOG_TRACE(msg, ...) DFX_UTILITIES_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
92
#define DFX_UTILITIES_LOG_DEBUG(msg, ...) DFX_UTILITIES_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
93
#define DFX_UTILITIES_LOG_INFO(msg, ...) DFX_UTILITIES_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
94
#define DFX_UTILITIES_LOG_WARN(msg, ...) DFX_UTILITIES_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
95
#define DFX_UTILITIES_LOG_ERROR(msg, ...) DFX_UTILITIES_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
96
#define DFX_UTILITIES_LOG_CRITICAL(msg, ...) DFX_UTILITIES_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
97
98
#define DFX_GRAPH_LOGGER() spdlog::get(::dfx::Utils::graphLoggerName)
99
#define DFX_GRAPH_LOG(level, msg, ...) DFX_LLOG(DFX_GRAPH_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
100
#define DFX_GRAPH_LOG_TRACE(msg, ...) DFX_GRAPH_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
101
#define DFX_GRAPH_LOG_DEBUG(msg, ...) DFX_GRAPH_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
102
#define DFX_GRAPH_LOG_INFO(msg, ...) DFX_GRAPH_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
103
#define DFX_GRAPH_LOG_WARN(msg, ...) DFX_GRAPH_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
104
#define DFX_GRAPH_LOG_ERROR(msg, ...) DFX_GRAPH_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
105
#define DFX_GRAPH_LOG_CRITICAL(msg, ...) DFX_GRAPH_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
106
107
#define DFX_SERVER_LOGGER() spdlog::get(::dfx::Utils::serverLoggerName)
108
#define DFX_SERVER_LOG(level, msg, ...) DFX_LLOG(DFX_SERVER_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
109
#define DFX_SERVER_LOG_TRACE(msg, ...) DFX_SERVER_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
110
#define DFX_SERVER_LOG_DEBUG(msg, ...) DFX_SERVER_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
111
#define DFX_SERVER_LOG_INFO(msg, ...) DFX_SERVER_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
112
#define DFX_SERVER_LOG_WARN(msg, ...) DFX_SERVER_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
113
#define DFX_SERVER_LOG_ERROR(msg, ...) DFX_SERVER_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
114
#define DFX_SERVER_LOG_CRITICAL(msg, ...) DFX_SERVER_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
115
116
#define DFX_NODE_LOGGER() spdlog::get(::dfx::Utils::nodeLoggerName)
117
#define DFX_NODE_LOG(level, msg, ...) do { ::dfx::Utils::ScopedMdc _("node", this->name()); DFX_LLOG(DFX_NODE_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__); } while (false)
118
#define DFX_NODE_LOG_TRACE(msg, ...) DFX_NODE_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
119
#define DFX_NODE_LOG_DEBUG(msg, ...) DFX_NODE_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
120
#define DFX_NODE_LOG_INFO(msg, ...) DFX_NODE_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
121
#define DFX_NODE_LOG_WARN(msg, ...) DFX_NODE_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
122
#define DFX_NODE_LOG_ERROR(msg, ...) DFX_NODE_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
123
#define DFX_NODE_LOG_CRITICAL(msg, ...) DFX_NODE_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
124
125
#define DFX_PCAPNG_LOGGER() spdlog::get(::dfx::Utils::pcapngLoggerName)
126
#define DFX_PCAPNG_LOG(level, msg, ...) DFX_LLOG(DFX_PCAPNG_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
127
#define DFX_PCAPNG_LOG_TRACE(msg, ...) DFX_PCAPNG_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
128
#define DFX_PCAPNG_LOG_DEBUG(msg, ...) DFX_PCAPNG_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
129
#define DFX_PCAPNG_LOG_INFO(msg, ...) DFX_PCAPNG_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
130
#define DFX_PCAPNG_LOG_WARN(msg, ...) DFX_PCAPNG_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
131
#define DFX_PCAPNG_LOG_ERROR(msg, ...) DFX_PCAPNG_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
132
#define DFX_PCAPNG_LOG_CRITICAL(msg, ...) DFX_PCAPNG_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
133
134
#define DFX_FDWATCH_LOGGER() spdlog::get(::dfx::Utils::fdwatchLoggerName)
135
#define DFX_FDWATCH_LOG(level, msg, ...) DFX_LLOG(DFX_FDWATCH_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
136
#define DFX_FDWATCH_LOG_TRACE(msg, ...) DFX_FDWATCH_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
137
#define DFX_FDWATCH_LOG_DEBUG(msg, ...) DFX_FDWATCH_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
138
#define DFX_FDWATCH_LOG_INFO(msg, ...) DFX_FDWATCH_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
139
#define DFX_FDWATCH_LOG_WARN(msg, ...) DFX_FDWATCH_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
140
#define DFX_FDWATCH_LOG_ERROR(msg, ...) DFX_FDWATCH_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
141
#define DFX_FDWATCH_LOG_CRITICAL(msg, ...) DFX_FDWATCH_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
142
143
#define DFX_CLIENT_LOGGER() spdlog::get(::dfx::Utils::clientLoggerName)
144
#define DFX_CLIENT_LOG(level, msg, ...) DFX_LLOG(DFX_CLIENT_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
145
#define DFX_CLIENT_LOG_TRACE(msg, ...) DFX_CLIENT_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
146
#define DFX_CLIENT_LOG_DEBUG(msg, ...) DFX_CLIENT_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
147
#define DFX_CLIENT_LOG_INFO(msg, ...) DFX_CLIENT_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
148
#define DFX_CLIENT_LOG_WARN(msg, ...) DFX_CLIENT_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
149
#define DFX_CLIENT_LOG_ERROR(msg, ...) DFX_CLIENT_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
150
#define DFX_CLIENT_LOG_CRITICAL(msg, ...) DFX_CLIENT_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
151
152
#define DFX_SUBPROCESS_LOGGER() spdlog::get(::dfx::Utils::subprocessLoggerName)
153
#define DFX_SUBPROCESS_LOG(level, msg, ...) DFX_LLOG(DFX_SUBPROCESS_LOGGER(), level, msg __VA_OPT__(,) __VA_ARGS__)
154
#define DFX_SUBPROCESS_LOG_TRACE(msg, ...) DFX_SUBPROCESS_LOG(spdlog::level::trace, msg __VA_OPT__(,) __VA_ARGS__)
155
#define DFX_SUBPROCESS_LOG_DEBUG(msg, ...) DFX_SUBPROCESS_LOG(spdlog::level::debug, msg __VA_OPT__(,) __VA_ARGS__)
156
#define DFX_SUBPROCESS_LOG_INFO(msg, ...) DFX_SUBPROCESS_LOG(spdlog::level::info, msg __VA_OPT__(,) __VA_ARGS__)
157
#define DFX_SUBPROCESS_LOG_WARN(msg, ...) DFX_SUBPROCESS_LOG(spdlog::level::warn, msg __VA_OPT__(,) __VA_ARGS__)
158
#define DFX_SUBPROCESS_LOG_ERROR(msg, ...) DFX_SUBPROCESS_LOG(spdlog::level::err, msg __VA_OPT__(,) __VA_ARGS__)
159
#define DFX_SUBPROCESS_LOG_CRITICAL(msg, ...) DFX_SUBPROCESS_LOG(spdlog::level::critical, msg __VA_OPT__(,) __VA_ARGS__)
dfx::Utils
Definition
SystemConfigCommandHandler.hpp:15
lib
dfx-utilities
Log.hpp
Generated by
1.14.0