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