ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
variables.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/// Copyright 2013-2026 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
9
10//==================================================================================================
11/// Definition of the main log-line format string for class #"textlogger::TextLogger;*"
12/// and its derivates.
13/// This struct is used to define an external #"alib_mod_variables;configuration variable"
14/// named #"alxcvALOX_LOGGERNAME_FORMAT".
15/// This variable can be accessed programatically
16/// with #"TextLogger::GetFormatMetaInfo" or by accessing the variable's value
17/// through the configuration object found in camp singleton #"alib::ALOX;2".
18//==================================================================================================
20 /// The line format specifies the (automated) log output that is prepended to each log line before
21 /// the log message itself. This format string can be changed after the creation
22 /// of a #"TextLogger".
23 ///
24 /// The string supports replacement variables that begin with a <c>\%</c> character:
25 /// Variable | Description
26 /// ---------|--------------------------------------------------------------------
27 /// \%SP: |The full path of the source file
28 /// \%Sp: |The trimmed path of the source file
29 /// \%SF: |The caller's source file name
30 /// \%Sf: |The caller's source file name without extension
31 /// \%SL: |The line number in the source file
32 /// \%SM: |The method name
33 /// &nbsp; | &nbsp;
34 /// \%TD: |The date the log call was invoked
35 /// \%TT: |Time of day the log call was invoked
36 /// \%TC: |Time elapsed since the Logger was created or its timer was reset
37 /// \%TL: |Time elapsed since the last log call
38 /// &nbsp; | &nbsp;
39 /// \%tN: |Thread name
40 /// \%tI: |Thread ID
41 /// &nbsp; | &nbsp;
42 /// \%V: |The verbosity. This is replaced by the corresponding strings found in fields #"VerbosityError", #"VerbosityWarning", #"VerbosityInfo" and #"VerbosityVerbose".
43 /// \%D: |Log domain
44 /// \%#: |The log call counter (like a line counter, but counting multi-lines as one)
45 /// \%An: |An auto-adjusted tabulator. This grows whenever it needs, but never shrinks. The optional integer number n specifies how much extra space is added when tab is adjusted. Setting this to a higher value avoids too many adjustments at the beginning of a log session.
46 /// \%LG: |The name of the \e Logger. This might be useful if multiple loggers write to the same output stream (e.g., Console).
47 /// \%LX: |The name of the \e Lox.
48 /// \%P: |The name of the process / application.
49 ///
50 /// Resourced default is
51 /// \code "%Sp/%SF(%SL):%A5%SM() %A5[%TC +%TL][%tN]%V[%D]%A1(%#): " \endcode
52 ///
53 /// If debug logging as well as release logging has scope information disabled
54 /// (see #"ALOX_DBG_LOG_CI" and #"ALOX_REL_LOG_CI"), then it defaults to:
55 /// <c>"[%TC +%TL][%tN]%V[%D]%A1(%#): "</c>
56 ///
57 /// \note
58 /// The use of <c>%%TD</c> and <c>%%TT</c> may become problematic and ambiguous if the
59 /// system clock is changed during software run. Especially for long-running background
60 /// software (daemons, servers, etc.), the software that uses \alox needs to provide
61 /// a strategy of synchronizing the clock with field
62 /// #"TextLogger::DateConverter".<br>
63 /// For some explanation of the problem see details of namespace #"alib::time;2".
65
66 /// The replacement for variable \c %%V in field #".Format" if \e Verbosity is \c Error.
67 /// Resourced as '[ERR]'.
69
70 /// The replacement for variable \c %%V in field #".Format" if \e Verbosity is \c Warning.
71 /// Resourced as '[WRN]'.
73
74 /// The replacement for variable \c %%V in field #".Format" if \e Verbosity is \c Info.
75 /// Resourced as ' '.
77
78 /// The replacement for variable \c %%V in field #".Format" if \e Verbosity is \c Verbose.
79 /// Resourced as to '[***]'.
81
82 /// Characters written after each <em>Log Statement</em>.
83 /// This may be used, for example, to reset colors and styles.
84 /// Note, that with multi-line <em>Log Statements</em>, the contents of this field is \b not
85 /// written at the end of each line, but only at the end of the last line.
86 /// To define characters that are written after each line of a multi-line
87 /// <em>Log Statement</em>, set field #".MsgSuffix".
88 ///
89 /// Defaults to empty string.
91
92
93 /// Constructor taking an object pool which is passed to each string member.
94 /// @param pool The pool object of the #"Configuration".
96 : Format (pool)
97 , VerbosityError (pool)
98 , VerbosityWarning (pool)
99 , VerbosityInfo (pool)
100 , VerbosityVerbose (pool)
101 , MsgSuffix (pool) {}
102}; // struct FormatMetaInfo
103
104//==================================================================================================
105/// Definition of date and time formats for class #"textlogger::TextLogger;*"
106/// and its derivates.
107/// This struct is used to define an external #"alib_mod_variables;configuration variable"
108/// named #"alxcvALOX_LOGGERNAME_FORMAT_DATE_TIME".
109/// This variable can be accessed programatically
110/// with #"TextLogger::GetFormatDate" or by accessing the variable's value
111/// through the configuration object found in camp singleton #"alib::ALOX;2".
112//==================================================================================================
114 /// Format string for the output of the log date. For more information, see
115 /// "Standard Date and Time Format Strings" in .NET StringBuilder.AppendFormat().
117
118 /// Format string for the output of the time of day. For more information, see
119 /// "Standard Date and Time Format Strings" in .NET StringBuilder.AppendFormat().
121
122 /// The word "Days" the out put of time elapsed (if longer than a day).
124
125 /// Constructor taking an object pool which is passed to each string member.
126 /// @param pool The pool object of the #"Configuration".
128 : Date (pool)
129 , TimeOfDay (pool)
130 , ElapsedDays(pool) {}
131}; // struct DateFormat
132
133//==================================================================================================
134/// Definition of the formats of time differences for class
135/// #"textlogger::TextLogger;*" and its derivates.
136/// This struct is used to define an external #"alib_mod_variables;configuration variable"
137/// named #"alxcvALOX_LOGGERNAME_FORMAT_TIME_DIFF".
138/// This variable can be accessed programatically
139/// with #"TextLogger::GetFormatTimeDiff" or by accessing the variable's value
140/// through the configuration object found in camp singleton #"alib::ALOX;2".
141//==================================================================================================
143 /// Minimum time difference to log in nanoseconds. Below that #".None" is written.
144 int64_t Minimum;
145
146 /// Output for time difference if below reasonable (measurable) minimum defined in #".Minimum".
148
149 /// Entity nanoseconds for time difference outputs below 1000 microsecond.
151
152 /// Entity microseconds for time difference outputs below 1000 microseconds.
154
155 /// Entity milliseconds for time difference outputs below 1000 milliseconds.
157
158 /// Format for time difference outputs between 10s and 99.9s.
160
161 /// Format for time difference outputs between 100s and 60 min.
163
164 /// Format for time difference outputs between 1h and 24h.
166
167 /// Format for time difference outputs of more than a day.
169
170 /// Constructor taking an object pool which is passed to each string member.
171 /// @param pool The pool object of the #"Configuration".
173 : None (pool)
174 , Nanos (pool)
175 , Micros(pool)
176 , Millis(pool)
177 , Secs (pool)
178 , Mins (pool)
179 , Hours (pool)
180 , Days (pool) {}
181};
182
183//==================================================================================================
184/// Definition of the multi-line message mode for class #"textlogger::TextLogger;*"
185/// and its derivates.
186/// This struct is used to define an external #"alib_mod_variables;configuration variable"
187/// named #"alxcvALOX_LOGGERNAME_FORMAT_MULTILINE".
188/// This variable can be accessed programatically
189/// with #"TextLogger::GetFormatMultiLine" or by accessing the variable's value
190/// through the configuration object found in camp singleton #"alib::ALOX;2".
191//==================================================================================================
193 /// Determines if multi-line messages should be split into different log lines. Possible
194 /// values are:
195 ///
196 /// - 0: No line split is performed, delimiters can be replaced by readable delimiters
197 /// (depending on setting of #".Delimiter" and #".DelimiterReplacement").
198 ///
199 /// - 1: Each log line contains all meta-information
200 ///
201 /// - 2: Starting with second log line, meta-information is replaced by blanks (default)
202 ///
203 /// - 3: The headline #".Headline" is logged and all lines of the multi-line
204 /// text are logged at position zero (without further meta-information)
205 ///
206 /// - 4: Just the multi-line text is logged, starting at column zero (no meta-information
207 /// is logged)
208 ///
209 /// \note In modes 3 and 4, no ESC::EOMETA is included at the beginning of the message.
210 /// Loggers that need such info, have to implement method
211 /// #"TextLogger::notifyMultiLineOp".
212 int Mode;
213
214 /// This is the string interpreted as line delimiter within log messages. If \e nulled, then
215 /// <c>'\\n'</c>, <c>'\\r'</c> or <c>'\\r\\n'</c> is recognized.<br>
216 /// Important: Can be set to an empty string, to stop any multi-line processing of
217 /// #"%TextLogger", even the replacements of the delimiter character.
219
220 /// Headline for multi-line messages (depending on #".Mode").
221 /// Defaults to "ALox: Multi-line message follows: "
223
224 /// Prefix for multi-line messages. This is also used if multi-line messages logging is
225 /// switched off (MultiLineMsgMode == 0) but replacing of a set MultiLineDelimiter takes
226 /// place.
227 /// Defaults to ">> ".
229
230 /// Suffix for multi-line messages. This is also used if multi-line messages logging is
231 /// switched off (MultiLineMsgMode == 0) and replacing of a set #".Delimiter"
232 /// takes place.<br>
233 /// Note that at the end of the last line, in addition #".Suffix" is added.<br>
234 /// Defaults to "".
236
237 /// This is the readable (!) separator string, for logging out multi-line messages into a
238 /// single line (#".Mode"==0).
239 /// Defaults to "\\r".
241
242 /// Constructor taking an object pool which is passed to each string member.
243 /// @param pool The pool object of the #"Configuration".
245 : Delimiter (pool)
246 , Headline (pool)
247 , Prefix (pool)
248 , Suffix (pool)
249 , DelimiterReplacement(pool) {}
250
251};
252
253//==================================================================================================
254/// Definition of further format options for class #"textlogger::TextLogger;*"
255/// and its derivates.
256/// This struct is used to define an external #"alib_mod_variables;configuration variable"
257/// named #"alxcvALOX_LOGGERNAME_FORMAT_OTHER".
258/// This variable can be accessed programatically
259/// with #"TextLogger::GetFormatOther" or by accessing the variable's value
260/// through the configuration object found in camp singleton #"alib::ALOX;2".
261//==================================================================================================
263 /// Replacement string if no source info is available.
265
266 /// Replacement string if no source info is available.
268
269 /// The minimum digits to write for the log number (if used in format string).
271
272 /// Constructor taking an object pool which is passed to each string member.
273 /// @param pool The pool object of the #"Configuration".
275 : NoSourceFileInfo(pool)
276 , NoMethodInfo (pool) {}
277}; // struct FormatOther
278
279
280//==================================================================================================
281/// Automatically detected field width and tab-stop positions for the meta-information part
282/// as well as the log message part, collected during the run of software.
283/// This struct is used to define an external #"alib_mod_variables;configuration variable"
284/// named #"alxcvALOX_LOGGERNAME_AUTO_SIZES".
285///
286/// This variable can be accessed programatically either with method
287/// #"TextLogger::GetAutoSizes" or by accessing the variable's value
288/// through the configuration object found in camp singleton #"alib::ALOX;2".
289///
290/// For almost all use cases, field #".Main" will work as expected, because the meta-information
291/// of log lines usually do not change. In other words, if they get changed, it is a good idea
292/// to invoke #"AutoSizes::Reset" on that field.
293///
294/// Field #".LogMessage" with built-in text loggers, is passed to field
295/// #"FormatterPythonStyle::Sizes;*" and thus is used to organize tab-stops and
296/// field widths of the log messages itself.<br>
297/// The field may be reset manually after (or before) a coherent set of log messages have
298/// been (respectively are to be) written. Such "coherent set" is, for example, the output of
299/// tabular data. If this is not done, a next table containing different data, would not be
300/// printed with correct field sizes in case the automatic tab-stops.
301///
302/// Also, it might be reasonable to invoke #"AutoSizes;Consolidate" one both
303/// objects from time to time, or in certain situations.
304///
305/// @see Variable #"alxcvALOX_LOGGERNAME_AUTO_SIZES".
306//==================================================================================================
308 /// The instance used with the meta info format string.
310
311 /// An #"%AutoSizes" object which is used to format the log message itself.
312 /// \note With the use of class #"textlogger::StandardConverter", this
313 /// instance is passed to the internal instance(s) of the
314 /// #"FormatterPythonStyle" used.
316
317 /// Determines whether changes should be written back to configuration sources, if possible.<br>
318 /// Defaults to \c true.
319 /// @see Methods #"Variable::IsWriteBack;*" and the virtual method used to
320 /// implement this feature: #"VMeta::isWriteBack;*".
321 bool WriteBack =true;
322}; // struct FormatAutoSizes
323
324//==================================================================================================
325/// A simple list of pairs of strings to search in log messages and their replacement value.
326/// This variable can be accessed programatically with
327/// #"TextLogger::GetReplacements" or by accessing the variable's value
328/// through the configuration object found in camp singleton #"alib::ALOX;2".
329//==================================================================================================
331 /// The list of pairs of replacement strings
332 std::vector<AStringPA, lang::StdAllocator<AStringPA, PoolAllocator>> Pairs;
333
334 /// Constructor taking an object pool which is passed to the string vector.
335 /// @param pool The pool object of the #"Configuration".
337 : Pairs(pool) {}
338};
339
340/// Parameters specific to colorful loggers. As of today, this simply has one attribute.
342 /// Denotes the use of light vs dark colors. Used with colorful descendants of class
343 /// #"textlogger::TextLogger".
344 enum class LightColorUsage {
345 Auto, ///< Automatic
346 Never, ///< Never use light colors
347 Foreground, ///< Use light colors for foreground
348 Background ///< Use light colors for background
349 };
350
351 LightColorUsage LCU= LightColorUsage::Auto; ///< Denotes use of light or dark colors.
352 ///< Defaults to \e Auto.
353};
354
355
356} // namespace [alib::lox::textlogger]
357
358DOX_MARKER([DOX_VARIABLES_DEFINETYPE1])
360DOX_MARKER([DOX_VARIABLES_DEFINETYPE1])
366ALIB_VARIABLES_DEFINE_TYPE ( alib::lox::textlogger::, ColorfulLoggerParameters ,A_CHAR("ALOXCLP") )
367
368// FormatAutoSizes (has writeback, no macro for that)
369#if !DOXYGEN
371struct VMeta_FormatAutoSizes : public VMeta {
372 ALIB_DLL String typeName () const override { return A_CHAR("ALOXAS"); }
373ALIB_DBG(ALIB_DLL const std::type_info& dbgTypeID() override { return typeid(lox::textlogger::FormatAutoSizes); } )
374 ALIB_DLL void construct(VDATA* obj, PoolAllocator&) override { new (obj) lox::textlogger::FormatAutoSizes(); }
375 ALIB_DLL void destruct (VDATA* obj, PoolAllocator&) override { reinterpret_cast<lox::textlogger::FormatAutoSizes*>(obj)->~FormatAutoSizes(); }
376 ALIB_DLL size_t size () override { static_assert(alignof(lox::textlogger::FormatAutoSizes) <= PoolAllocator::MAX_ALIGNMENT); return (std::max)( sizeof(lox::textlogger::FormatAutoSizes), sizeof(void*) ); }
377 ALIB_DLL void imPort (VDATA*, Configuration&, const StringEscaper&, const String&) override;
378 ALIB_DLL void exPort (VDATA*, Configuration&, const StringEscaper&, AString&) override;
379 ALIB_DLL bool isWriteBack(VDATA* obj) const override { return reinterpret_cast<lox::textlogger::FormatAutoSizes*>(obj)->WriteBack; }
380};}
381#endif // !DOXYGEN
382
#define ALIB_DLL
#define A_CHAR(STR)
#define ALIB_EXPORT
#define ALIB_DBG(...)
#define ALIB_ENUMS_ASSIGN_RECORD(TEnum, TRecord)
This namespaces defines class #"%TextLogger" and its helpers.
Definition loxpimpl.hpp:13
Definition alox.cpp:14
strings::TAString< character, PoolAllocator > AStringPA
Type alias in namespace #"%alib".
strings::util::AutoSizes AutoSizes
Type alias in namespace #"%alib".
monomem::TPoolAllocator< MonoAllocator > PoolAllocator
strings::TString< character > String
Type alias in namespace #"%alib".
Definition string.hpp:2165
strings::TAString< nchar, PoolAllocator > NAStringPA
Type alias in namespace #"%alib".
Parameters specific to colorful loggers. As of today, this simply has one attribute.
AutoSizes Main
The instance used with the meta info format string.
AStringPA ElapsedDays
The word "Days" the out put of time elapsed (if longer than a day).
FormatMetaInfo(PoolAllocator &pool)
Definition variables.hpp:95
NAStringPA NoMethodInfo
Replacement string if no source info is available.
FormatOther(PoolAllocator &pool)
NAStringPA NoSourceFileInfo
Replacement string if no source info is available.
int LogNumberMinDigits
The minimum digits to write for the log number (if used in format string).
AStringPA Nanos
Entity nanoseconds for time difference outputs below 1000 microsecond.
AStringPA None
Output for time difference if below reasonable (measurable) minimum defined in #"....
AStringPA Mins
Format for time difference outputs between 100s and 60 min.
AStringPA Millis
Entity milliseconds for time difference outputs below 1000 milliseconds.
int64_t Minimum
Minimum time difference to log in nanoseconds. Below that #".None" is written.
AStringPA Days
Format for time difference outputs of more than a day.
AStringPA Secs
Format for time difference outputs between 10s and 99.9s.
AStringPA Hours
Format for time difference outputs between 1h and 24h.
AStringPA Micros
Entity microseconds for time difference outputs below 1000 microseconds.
Replacements(PoolAllocator &pool)
std::vector< AStringPA, lang::StdAllocator< AStringPA, PoolAllocator > > Pairs
The list of pairs of replacement strings.
#define ALIB_VARIABLES_DEFINE_TYPE_WITH_POOL_CONSTRUCTOR(Namespace, CPPName, CfgTypeString)
#define ALIB_VARIABLES_DEFINE_TYPE(Namespace, CPPName, CfgTypeString)