CVB++ 15.0
Loading...
Searching...
No Matches
module.hpp
1#pragma once
2
3#include "telemetry.hpp"
4
5// hide inline namespace for documentation
6// clang-format off
7#define CVB_TELEMETRY_BEGIN_INLINE_NS \
8 inline namespace CVB_TELEMETRY_MODULE_NAMESPACE \
9 {
10#define CVB_TELEMETRY_END_INLINE_NS }
11
12#ifndef CVB_TELEMETRY_MODULE_NAMESPACE
13# define CVB_TELEMETRY_MODULE_NAMESPACE undefined
14#endif;
15#define CVB_TELEMETRY_END_INLINE_NS }
16// clang-format on
17
18namespace Cvb
19{
20 CVB_BEGIN_INLINE_NS
21
22 namespace Telemetry
23 {
24 class Span;
25 class Log;
26
27 CVB_TELEMETRY_BEGIN_INLINE_NS
28
30
39 class Module
40 {
41 friend Span;
42 friend Log;
43
44 public:
46
53 static Module &Get();
54
55 Module(const std::string &name, const std::string &version)
56 {
57 CExports::CVTGetModule(name.c_str(), version.c_str(), handle_, config_);
58 }
59
60 Module(const Module &) = delete;
61 Module &operator=(const Module &) = delete;
62 Module(Module &&) = delete;
63 Module &operator=(Module &&) = delete;
64 ~Module() = default;
65
67
71 bool WouldTrace() const noexcept
72 {
73 return CExports::CVTTR_On == config_.Tracing;
74 }
75
77
81 bool WouldLog() const noexcept
82 {
83 return config_.Logging == CExports::CVTLO_On;
84 }
85
87
93 bool WouldLogAtLevel(Telemetry::LogLevel logLevel) const noexcept
94 {
95 return WouldLog() && config_.LogLevel <= static_cast<CExports::CVTLogLevel>(logLevel);
96 }
97
99
103 bool WouldLogDebug() const noexcept
104 {
106 }
107
109
113 bool WouldLogInfo() const noexcept
114 {
116 }
117
119
123 bool WouldLogWarning() const noexcept
124 {
126 }
127
129
133 bool WouldLogError() const noexcept
134 {
136 }
137
139
143 bool WouldLogFatal() const noexcept
144 {
146 }
147
148 private:
149 void *Handle() const noexcept
150 {
151 return handle_;
152 }
153
154 CExports::CVTModuleConfig config_;
155 CExports::CVTMODULE handle_ = nullptr;
156 };
157
158 CVB_TELEMETRY_END_INLINE_NS
159 } // namespace Telemetry
160
161 CVB_END_INLINE_NS
162} // namespace Cvb
A log object to stream messages.
Definition log.hpp:20
A telemetry module or artifact.
Definition module.hpp:40
bool WouldLogFatal() const noexcept
Get if fatal logs are active.
Definition module.hpp:143
static Module & Get()
Get the module singleton.
bool WouldLogInfo() const noexcept
Get if info logs are active.
Definition module.hpp:113
bool WouldLog() const noexcept
Get if logs are active.
Definition module.hpp:81
bool WouldTrace() const noexcept
Get if traces are active.
Definition module.hpp:71
bool WouldLogAtLevel(Telemetry::LogLevel logLevel) const noexcept
Get if logs at the specified level are active.
Definition module.hpp:93
bool WouldLogWarning() const noexcept
Get if warning logs are active.
Definition module.hpp:123
bool WouldLogError() const noexcept
Get if error logs are active.
Definition module.hpp:133
bool WouldLogDebug() const noexcept
Get if debug logs are active.
Definition module.hpp:103
A span object to report traces.
Definition span.hpp:19
Namespace for telemetry.
Definition attribute_map.hpp:16
LogLevel
Log level for telemetry.
Definition telemetry.hpp:32
@ LevelFatal
Logs indicating errors, that cannot be ignored.
Definition telemetry.hpp:42
@ LevelInfo
Logs informing about the current state.
Definition telemetry.hpp:36
@ LevelWarn
Logs warning about the current state, as it is out of the ordinary.
Definition telemetry.hpp:38
@ LevelDebug
Logs for debugging, these should be avoided especially in a critical code paths.
Definition telemetry.hpp:34
@ LevelError
Logs indicating errors, that may be ignored.
Definition telemetry.hpp:40
Root namespace for the Image Manager interface.
Definition version.hpp:11