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
91 bool WouldLogDebug() const noexcept
92 {
93 return WouldLog() && config_.LogLevel <= CExports::CVTLL_Debug;
94 }
95
97
101 bool WouldLogInfo() const noexcept
102 {
103 return WouldLog() && config_.LogLevel <= CExports::CVTLL_Info;
104 }
105
107
111 bool WouldLogWarning() const noexcept
112 {
113 return WouldLog() && config_.LogLevel <= CExports::CVTLL_Warning;
114 }
115
117
121 bool WouldLogError() const noexcept
122 {
123 return WouldLog() && config_.LogLevel <= CExports::CVTLL_Error;
124 }
125
127
131 bool WouldLogFatal() const noexcept
132 {
133 return WouldLog() && config_.LogLevel <= CExports::CVTLL_Fatal;
134 }
135
136 private:
137 void *Handle() const noexcept
138 {
139 return handle_;
140 }
141
142 CExports::CVTModuleConfig config_;
143 CExports::CVTMODULE handle_ = nullptr;
144 };
145
146 CVB_TELEMETRY_END_INLINE_NS
147 } // namespace Telemetry
148
149 CVB_END_INLINE_NS
150} // 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:131
static Module & Get()
Get the module singleton.
bool WouldLogInfo() const noexcept
Get if info logs are active.
Definition module.hpp:101
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 WouldLogWarning() const noexcept
Get if warning logs are active.
Definition module.hpp:111
bool WouldLogError() const noexcept
Get if error logs are active.
Definition module.hpp:121
bool WouldLogDebug() const noexcept
Get if debug logs are active.
Definition module.hpp:91
A span object to report traces.
Definition span.hpp:19
Namespace for telemetry.
Definition attribute_map.hpp:16
Root namespace for the Image Manager interface.
Definition version.hpp:11