diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-22 18:22:39 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-22 18:22:39 +0100 |
commit | b2ad8f785e801a35cadf254d827f56d648be510c (patch) | |
tree | 4eeb1e3eefb02c40dac40469c0fae5ad91feb3e3 /common/log.h | |
parent | 1fe8664ec74165fc3f250098609ea0e049e3adc8 (diff) | |
download | sink-b2ad8f785e801a35cadf254d827f56d648be510c.tar.gz sink-b2ad8f785e801a35cadf254d827f56d648be510c.zip |
Introduced Log::Context
To have hierarchical debug output we have to pass around something at
run-time, there is no reasonable alternative. Log::Context provides the
identifier to do just that and largely replaces the debug component
idea.
Diffstat (limited to 'common/log.h')
-rw-r--r-- | common/log.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/common/log.h b/common/log.h index f47a3ae..9063ac8 100644 --- a/common/log.h +++ b/common/log.h | |||
@@ -6,6 +6,14 @@ | |||
6 | namespace Sink { | 6 | namespace Sink { |
7 | namespace Log { | 7 | namespace Log { |
8 | 8 | ||
9 | struct Context { | ||
10 | Context() = default; | ||
11 | QByteArray name; | ||
12 | Context subContext(const QByteArray &sub) const { | ||
13 | return Context{name + "." + sub}; | ||
14 | } | ||
15 | }; | ||
16 | |||
9 | enum DebugLevel | 17 | enum DebugLevel |
10 | { | 18 | { |
11 | Trace, | 19 | Trace, |
@@ -91,6 +99,11 @@ static const char *getComponentName() { return nullptr; } | |||
91 | #define SinkWarning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName()) | 99 | #define SinkWarning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName()) |
92 | #define SinkError() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName()) | 100 | #define SinkError() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName()) |
93 | 101 | ||
102 | #define SinkTraceCtx(CTX) Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, CTX.name, getComponentName()) | ||
103 | #define SinkLogCtx(CTX) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, CTX.name, getComponentName()) | ||
104 | #define SinkWarningCtx(CTX) Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, CTX.name, getComponentName()) | ||
105 | #define SinkErrorCtx(CTX) Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, CTX.name, getComponentName()) | ||
106 | |||
94 | #define SINK_DEBUG_AREA(AREA) static constexpr const char* s_sinkDebugArea{AREA}; | 107 | #define SINK_DEBUG_AREA(AREA) static constexpr const char* s_sinkDebugArea{AREA}; |
95 | #define SINK_DEBUG_COMPONENT(COMPONENT) const char* getComponentName() const { return COMPONENT; }; | 108 | #define SINK_DEBUG_COMPONENT(COMPONENT) const char* getComponentName() const { return COMPONENT; }; |
96 | #define SINK_DEBUG_COMPONENT_STATIC(COMPONENT) static const char* getComponentName() { return COMPONENT; }; | 109 | #define SINK_DEBUG_COMPONENT_STATIC(COMPONENT) static const char* getComponentName() { return COMPONENT; }; |