ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alox/alox.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header file is part of module \alib_alox of the \aliblong.
4///
5/// \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#ifndef HPP_ALIB_ALOX
9#define HPP_ALIB_ALOX 1
10#pragma once
11#if !defined(DOXYGEN)
12# include "alib/alib.hpp"
13#endif
14
16
17#include "alib/config/priority.hpp"
18
19namespace alib { namespace lox {
20
21class Lox;
22
23//==================================================================================================
24/// This enum is used in \alox to control the "verbosity" or "verboseness" of the log output.
25/// The values herein - apart from special value 'Off' - are sorted in the following order
26/// - Verbose (highest level)
27/// - Info
28/// - Warning
29/// - Error (lowest level).
30///
31/// A value of this set is provided to \alox in two different ways:
32/// First, all methods of class \ref alib::lox::Lox "Lox" that execute a log operation
33/// assign a value of this enum to the <em>Log Statement</em>. Secondly, methods
34/// \ref alib::lox::Lox::SetVerbosity "Lox::SetVerbosity", are defining the 'accepted'
35/// <em>minimal Verbosity</em> for a pair of <em><Logger/%Log Domain></em>.
36///
37/// \alox, when executing a statement, checks both values against each other.
38/// A <em>Log Statement</em> is executed, when the <em><Logger/%Log Domain></em> setting is set
39/// to the same or a 'higher level'. For example if a <em><Logger/%Log Domain></em> setting is
40/// \b %Warning, then <em>Log Statements</em> with associated \e %Verbosity \b %Warning and
41/// \b %Error are executed and those with \b %Info and \b %Verbose are suppressed.
42///
43/// If special value \b %Off is used with \alib{lox;Lox::SetVerbosity}, all logging is switched off
44/// for this pair of <em><Logger/%Log Domain></em>.
45///
46/// Some of the <em>Log Statements</em> accept the parameter directly (e.g.
47/// \ref alib::lox::Lox::Entry "Lox::Entry",
48/// \ref alib::lox::Lox::Once "Lox::Once" and
49/// \ref alib::lox::Lox::If "Lox::If"), others inherently use the right value as their method
50/// name suggests (e.g.
51/// \ref alib::lox::Lox::Error "Lox::Error",
52/// \ref alib::lox::Lox::Warning "Lox::Warning",
53/// \ref alib::lox::Lox::Info "Lox::Info",
54/// \ref alib::lox::Lox::Verbose "Lox::Verbose" and
55/// \ref alib::lox::Lox::Assert "Lox::Assert"). The latter group of methods do not support
56/// parameter \b %Off.
57///
58/// If special value \b %Off is used with those <em>Log Statements</em>, that allow to specify the
59/// \e %Verbosity as a parameter, the <em>Log Statement</em> is never executed This is useful if the
60/// parameter is determined at run-time, depending on the state of an application.
61//==================================================================================================
62enum class Verbosity : uint8_t
63{
64 /// The 'highest' level of \e %Verbosity.
65 /// Statements with this value associated are logged only if a <em>%Log Domain</em> is set to
66 /// \b %Verbose as well.
67 Verbose,
68
69 /// The standard \e Verbosity for normal log output statements.
70 /// Logged if a <em>%Log Domain</em> is set to \b %Info or \b %Verbose.
71 Info,
72
73 /// A \e Verbosity for warning messages, hence things that might lead to errors or are not
74 /// welcome for other reasons, but maybe are not errors.<br>
75 /// Logged if a <em>%Log Domain</em> is set to \b %Warning, \b %Info or \b %Verbose.
76 Warning,
77
78 /// A \e Verbosity for error messages.
79 /// It is suppressed only if a <em>%Log Domain</em>'s setting is \b %Off.
80 Error,
81
82 /// Statements with this value associated are never logged (useful if \e %Verbosity is
83 /// evaluated at run-time). <em>%Log Domains</em> with this setting do not execute any
84 /// <em>Log Statement</em>.
85 Off
86};
87
88
89//==================================================================================================
90/// These are definitions that are used as a parameter to certain \alox methods to denote
91/// the \e Scope of a setting. \e Scopes are dependent of the programming language
92/// and hence differ slightly from each other in the different versions of \alox.
93///
94/// This enumeration is an \alib{enums;T_EnumIsArithmetical;ALib arithmetical enum}. However,
95/// the addition of values is only allowed with the last element, \b Path. By adding integer
96/// values, the Nth parent directory of a source file's location are addressed. As an example,
97/// invocations like this are used to select the source directory two levels above the source
98/// code file for a prefix scope:
99///
100/// lox->SetPrefix( "#> ", Scope::Path + 2 );
101///
102/// \note
103/// \alox for C++ implements scope mechanisms using scope information generated by the
104/// preprocessor.
105/// By default, debug logging supports such 'caller information', while release logging
106/// does not.<br>
107/// Therefore, in release-logging, the use of \e Scopes 'Path', 'Filename' and
108/// 'Method' will just default to an empty scope and therefore the all reflect the same,
109/// shared scope, which is not very helpful. Therefore, for standard release logging,
110/// the use of the scope mechanisms should be be avoided, unless scope information is
111/// explicitly enabled.<br>
112/// For more information on how to change the defaults, see documentation of preprocessor
113/// symbols \ref ALOX_DBG_LOG_CI and \ref ALOX_REL_LOG_CI.
114///
115/// For more information on \e Scopes consult the \ref alib_mod_alox.
116//==================================================================================================
117enum class Scope
118{
119 /// Denotes the global (singleton) scope.
120 Global,
121
122 /// Denotes the actual thread as the scope. When used with <em>Scope Domains</em>,
123 /// 'inner' scopes can be defined optionally by multiple definitions.
125
126 /// Denotes the actual source file as the scope.
127 Filename,
128
129 /// Denotes the actual method as the scope.
130 Method,
131
132 /// Denotes the actual thread as the scope. When used with <em>Scope Domains</em>,
133 /// 'inner' scopes can be defined optionally by multiple definitions.
135
136 /// Denotes the actual source path as the scope. By adding positive integral values
137 /// to this element (the enum type is an \alib{enums;T_EnumIsArithmetical;ALib arithmetical enum}),
138 /// 'outer' \e Scopes of this scope level itself can be defined using parent directories
139 /// of the path.
140 Path
141};
142
143//==================================================================================================
144/// This class defines "escape sequences" that influence the formatting of log output.
145/// Specific implementations of class
146/// \ref alib::lox::detail::Logger "Logger"
147/// have to convert or interpret this classes definitions of escape sequences
148/// when processing log data. If no formatting of the output is supported by a specific Logger
149/// implementation, such logger should filter and discard escape sequences defined here.
150///
151/// The sequences are similar to ANSI Escape sequences and logger classes that
152/// log to 'VT100' compatible terminals will simply convert them.
153///
154/// The name of the class was intentionally chosen to be short, because the escape codes
155/// defined with this class will be concatenated to log strings like that:
156///
157/// \snippet "ut_alox_dox.cpp" DOX_ALOX_ESC
158///
159/// \note
160/// With the introduction of own, \alox specific escape codes, software that uses ALox becomes
161/// independent of any underlying, platform-specific sequences. For example, \alox is not relying
162/// on ANSI color codes, which are not supported by colorful Windows consoles. Instead, on each
163/// platform, dedicated Loggers will perform the translation of \alox codes to platform-specific
164/// ones.
165//==================================================================================================
166class ESC
167{
168 public:
169 static constexpr character RED [4]{ A_CHAR("\033c0") }; ///< Select red color for foreground.
170 static constexpr character GREEN [4]{ A_CHAR("\033c1") }; ///< Select green color for foreground.
171 static constexpr character YELLOW [4]{ A_CHAR("\033c2") }; ///< Select yellow color for foreground.
172 static constexpr character BLUE [4]{ A_CHAR("\033c3") }; ///< Select blue color for foreground.
173 static constexpr character MAGENTA [4]{ A_CHAR("\033c4") }; ///< Select magenta color for foreground.
174 static constexpr character CYAN [4]{ A_CHAR("\033c5") }; ///< Select cyan color for foreground.
175 static constexpr character BLACK [4]{ A_CHAR("\033c6") }; ///< Select black color for foreground.
176 static constexpr character WHITE [4]{ A_CHAR("\033c7") }; ///< Select white color for foreground.
177 static constexpr character GRAY [4]{ A_CHAR("\033c8") }; ///< Select gray color for foreground.
178 static constexpr character FG_RESET [4]{ A_CHAR("\033c9") }; ///< Select std color for foreground.
179
180 static constexpr character BG_RED [4]{ A_CHAR("\033C0") }; ///< Select red color for background.
181 static constexpr character BG_GREEN [4]{ A_CHAR("\033C1") }; ///< Select green color for background.
182 static constexpr character BG_YELLOW [4]{ A_CHAR("\033C2") }; ///< Select yellow color for background.
183 static constexpr character BG_BLUE [4]{ A_CHAR("\033C3") }; ///< Select blue color for background.
184 static constexpr character BG_MAGENTA [4]{ A_CHAR("\033C4") }; ///< Select blue color for background.
185 static constexpr character BG_CYAN [4]{ A_CHAR("\033C5") }; ///< Select blue color for background.
186 static constexpr character BG_BLACK [4]{ A_CHAR("\033C6") }; ///< Select red color for background.
187 static constexpr character BG_WHITE [4]{ A_CHAR("\033C7") }; ///< Select blue color for background.
188 static constexpr character BG_GRAY [4]{ A_CHAR("\033C8") }; ///< Select gray color for background.
189 static constexpr character BG_RESET [4]{ A_CHAR("\033C9") }; ///< Select std color for background.
190
191 static constexpr character BOLD [4]{ A_CHAR("\033sB") }; ///< Select bold font style.
192 static constexpr character ITALICS [4]{ A_CHAR("\033sI") }; ///< Select italics font style.
193 static constexpr character STYLE_RESET[4]{ A_CHAR("\033sr") }; ///< Select standard font style.
194 static constexpr character RESET [4]{ A_CHAR("\033sa") }; ///< Reset color and style.
195
196 static constexpr character URL_START [4]{ A_CHAR("\033lS") }; ///< Mark the start of an URL.
197 static constexpr character URL_END [4]{ A_CHAR("\033lE") }; ///< Mark the end of an URL.
198 static constexpr character TAB [4]{ A_CHAR("\033t0") }; ///< Go to next tab. Usually, text loggers will increase the tab position automatically.
199
200 static constexpr character EOMETA [4]{ A_CHAR("\033A0") }; ///< End of meta-information in log string
201
202 //==============================================================================================
203 /// Replaces ESC codes in a string reversely to "ESC::XXX".
204 /// @param target The string to replace in.
205 /// @param startIdx The index to start searching for ESC codes.
206 //==============================================================================================
208 static void ReplaceToReadable( AString& target, integer startIdx );
209}; // class ESC
210
211} // namespace alib[::lox]
212
213
214/// Type alias in namespace \b alib.
216
217/// Type alias in namespace \b alib.
219
220/// Type alias in namespace \b alib.
222
223} // namespace [alib]
224
225
229 ALIB_COMMA alib::config::Priority> , vt_lox_pair_verby_prio )
230
231
235
236
237
238// #################################################################################################
239// include Log and Lox classes
240// #################################################################################################
241#include "alib/alox/macros.inl"
242
243#if (ALIB_DEBUG && ALOX_DBG_LOG) || ALOX_REL_LOG
244# include "alib/alox/log.inl"
245# include "alib/alox/lox.inl"
246#endif
247
248#endif // HPP_ALIB_ALOX
249
static constexpr character BG_BLUE[4]
Select blue color for background.
static constexpr character EOMETA[4]
End of meta-information in log string.
static constexpr character URL_END[4]
Mark the end of an URL.
static constexpr character FG_RESET[4]
Select std color for foreground.
static constexpr character BG_GREEN[4]
Select green color for background.
static constexpr character TAB[4]
Go to next tab. Usually, text loggers will increase the tab position automatically.
static constexpr character RED[4]
Select red color for foreground.
static ALIB_API void ReplaceToReadable(AString &target, integer startIdx)
Definition aloxcamp.cpp:413
static constexpr character BG_BLACK[4]
Select red color for background.
static constexpr character ITALICS[4]
Select italics font style.
static constexpr character MAGENTA[4]
Select magenta color for foreground.
static constexpr character BG_WHITE[4]
Select blue color for background.
static constexpr character BG_MAGENTA[4]
Select blue color for background.
static constexpr character URL_START[4]
Mark the start of an URL.
static constexpr character GRAY[4]
Select gray color for foreground.
static constexpr character CYAN[4]
Select cyan color for foreground.
static constexpr character BG_RED[4]
Select red color for background.
static constexpr character BG_CYAN[4]
Select blue color for background.
static constexpr character GREEN[4]
Select green color for foreground.
static constexpr character YELLOW[4]
Select yellow color for foreground.
static constexpr character RESET[4]
Reset color and style.
static constexpr character BLUE[4]
Select blue color for foreground.
static constexpr character BLACK[4]
Select black color for foreground.
static constexpr character BG_YELLOW[4]
Select yellow color for background.
static constexpr character STYLE_RESET[4]
Select standard font style.
static constexpr character BG_RESET[4]
Select std color for background.
static constexpr character WHITE[4]
Select white color for foreground.
static constexpr character BOLD[4]
Select bold font style.
static constexpr character BG_GRAY[4]
Select gray color for background.
This class acts as a container for Loggers and provides a convenient interface to logging.
Definition lox.inl:58
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:223
#define A_CHAR(STR)
#define ALIB_ENUMS_ASSIGN_RECORD(TEnum, TRecord)
Definition records.hpp:712
#define ALIB_API
Definition alib.hpp:639
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
Definition vtable.inl:460
#define ALIB_ENUMS_MAKE_ARITHMETICAL(TEnum)
#define ALIB_COMMA
Definition alib.hpp:982
@ Filename
Denotes the actual source file as the scope.
@ Method
Denotes the actual method as the scope.
@ Global
Denotes the global (singleton) scope.
Definition alib.cpp:69
characters::character character
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:273