CppTrail
Loading...
Searching...
No Matches
def.h
Go to the documentation of this file.
1
10#ifndef CPPTRAIL_DEF_H
11#define CPPTRAIL_DEF_H
12
13#if __cplusplus >= 201703L
14#include <string_view>
15#endif
16
17#include <array>
18#include <string>
19
20#include "cpptrail/utf42.h"
21
26namespace CppTrail {
31 enum class Status {
32 RUNNING,
33 STOPPED,
34 BROKEN,
36 };
37
42 enum class Level {
43 SUCCESS,
44 TRACE,
45 DEBUG,
46 INFO,
47 MESSAGE,
48 WARNING,
49 ERROR,
50 CRITICAL,
51 FATAL,
52 };
53
58 namespace Detail {
63 template<typename char_t>
64 struct LevelName {
69#if __cplusplus >= 201703L
70 using string_view_type = std::basic_string_view<char_t>;
71#else
73#endif
74
80 static std::basic_string<char_t> getName(Level nLevel) {
81 if (nLevel > Level::FATAL) return std::basic_string<char_t>{};
82#if __cplusplus >= 201703L
83 return std::basic_string<char_t>{NAMES[static_cast<std::size_t>(nLevel)]};
84#else
85 const auto sData = getNameView14(nLevel);
86 return {sData.data(), sData.length()};
87#endif
88 }
89
90#if __cplusplus >= 201703L
96 static std::basic_string_view<char_t> getNameView(Level nLevel) noexcept {
97 if (nLevel > Level::FATAL) return std::basic_string_view<char_t>{};
98 return NAMES[static_cast<std::size_t>(nLevel)];
99 }
100
102 constexpr static std::array<string_view_type, 9> NAMES = {
103 make_poly_enc(char_t, "SUCCESS"),
104 make_poly_enc(char_t, "TRACE"),
105 make_poly_enc(char_t, "DEBUG"),
106 make_poly_enc(char_t, "INFO"),
107 make_poly_enc(char_t, "MESSAGE"),
108 make_poly_enc(char_t, "WARNING"),
109 make_poly_enc(char_t, "ERROR"),
110 make_poly_enc(char_t, "CRITICAL"),
111 make_poly_enc(char_t, "FATAL"),
112 };
113#else
120 static string_view_type getNameView14(Level nLevel) noexcept {
121 switch (nLevel) {
122 case Level::SUCCESS: return make_poly_enc(char_t, "SUCCESS");
123 case Level::TRACE: return make_poly_enc(char_t, "TRACE");
124 case Level::DEBUG: return make_poly_enc(char_t, "DEBUG");
125 case Level::INFO: return make_poly_enc(char_t, "INFO");
126 case Level::MESSAGE: return make_poly_enc(char_t, "MESSAGE");
127 case Level::WARNING: return make_poly_enc(char_t, "WARNING");
128 case Level::ERROR: return make_poly_enc(char_t, "ERROR");
129 case Level::CRITICAL: return make_poly_enc(char_t, "CRITICAL");
130 case Level::FATAL: return make_poly_enc(char_t, "FATAL");
131 default: return make_poly_enc(char_t, "");
132 }
133 }
134#endif
135 };
136 }
137
147 inline std::string getName(const Level nLevel) {
149 }
150
151#if __cplusplus >= 202002L
157 inline std::u8string u8getName(const Level nLevel) {
159 }
160#endif
161
167 inline std::u16string u16getName(const Level nLevel) {
169 }
170
176 inline std::u32string u32getName(const Level nLevel) {
178 }
179
186 template<typename char_t>
187 std::basic_string<char_t> tgetName(const Level nLevel) {
189 }
190
193#if __cplusplus >= 201703L
204 inline std::string_view getNameView(const Level nLevel) {
206 }
207
208#if __cplusplus >= 202002L
214 inline std::u8string_view u8getNameView(const Level nLevel) {
216 }
217#endif
218
224 inline std::u16string_view u16getNameView(const Level nLevel) {
226 }
227
233 inline std::u32string_view u32getNameView(const Level nLevel) {
235 }
236
243 template<typename char_t>
244 std::basic_string_view<char_t> tgetNameView(const Level nLevel) {
246 }
247
249#endif
250}
251
252#endif
Root namespace for the CppTrail logging library.
Definition async_logger.h:24
std::string_view getNameView(const Level nLevel)
Gets a view of the level name.
Definition def.h:204
std::u16string u16getName(const Level nLevel)
Gets the level name as a std::u16string.
Definition def.h:167
std::u16string_view u16getNameView(const Level nLevel)
Gets a UTF-16 view of the level name.
Definition def.h:224
Level
Severity levels for log entries.
Definition def.h:42
@ WARNING
Indications of potential issues or non-critical failures.
@ FATAL
Terminal errors that require immediate application termination.
@ TRACE
Extremely fine-grained diagnostic events (wire-level).
@ INFO
General operational messages about application progress.
@ MESSAGE
High-level communication or protocol-specific messages.
@ CRITICAL
Severe failures that may lead to localized component shutdown.
@ ERROR
Significant issues that require attention but allow continued execution.
@ SUCCESS
Positive confirmation of a successful operation.
@ DEBUG
Information useful for application debugging.
std::u8string_view u8getNameView(const Level nLevel)
Gets a UTF-8 view of the level name.
Definition def.h:214
std::u32string u32getName(const Level nLevel)
Gets the level name as a std::u32string.
Definition def.h:176
std::string getName(const Level nLevel)
Gets the level name as a std::string.
Definition def.h:147
std::u32string_view u32getNameView(const Level nLevel)
Gets a UTF-32 view of the level name.
Definition def.h:233
std::basic_string< char_t > tgetName(const Level nLevel)
Template version for generic character types (allocating).
Definition def.h:187
std::basic_string_view< char_t > tgetNameView(const Level nLevel)
Template version for generic character types (non-allocating).
Definition def.h:244
std::u8string u8getName(const Level nLevel)
Gets the level name as a std::u8string.
Definition def.h:157
Status
Represents the current operational state of a Logger implementation.
Definition def.h:31
@ TRASCENDENT
The logger operates outside standard lifecycle management.
@ STOPPED
The logger has been gracefully shut down.
@ BROKEN
The logger encountered a fatal error (e.g., IO failure).
@ RUNNING
The logger is active and processing entries.
Internal implementation details. Not intended for direct public use.
std::basic_string_view< char_t > basic_string_view
String view type for poly_enc.
Definition utf42.h:179
Template utility to map Level enums to string representations.
Definition def.h:64
std::basic_string_view< char_t > string_view_type
Maps to std::string_view on C++17+, or CppTrail's fallback view on older standards.
Definition def.h:70
static std::basic_string_view< char_t > getNameView(Level nLevel) noexcept
Retrieves a view of the level name.
Definition def.h:96
static constexpr std::array< string_view_type, 9 > NAMES
Static array of localized/encoded level names.
Definition def.h:102
static std::basic_string< char_t > getName(Level nLevel)
Retrieves the level name as a basic_string.
Definition def.h:80
Compile-time polymorphic string literal selection across character encodings.
#define make_poly_enc(char_t, lit)
Creates a compile-time polymorphic encoded string literal.
Definition utf42.h:80