ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
textlogger.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_ALOX_DETAIL_TEXTLOGGER_TEXTLOGGER
9#define HPP_ALOX_DETAIL_TEXTLOGGER_TEXTLOGGER 1
10
11#if !defined (HPP_ALIB_ALOX)
12 #include "alib/alox/alox.hpp"
13#endif
14
15// #################################################################################################
16// includes
17// #################################################################################################
18#if !defined (HPP_ALOX_DETAIL_LOGGER)
20#endif
21
22#if !defined (HPP_ALIB_CAMP_CALENDAR)
24#endif
25
26#if !defined (HPP_ALIB_TIME_TICKSCONVERTER)
28#endif
29
30#if !defined (HPP_ALIB_LANG_FORMAT_FORMATTER_JAVASTYLE)
32#endif
33
34#if !defined (HPP_ALIB_LANG_FORMAT_FORMATTER_PYTHONSTYLE)
36#endif
37
38// #################################################################################################
39// forward declarations
40// #################################################################################################
41
42namespace alib { namespace lox { namespace detail {
43/** ************************************************************************************************
44 * This namespaces defines class \b TextLogger and its helpers.
45 **************************************************************************************************/
46namespace textlogger {
47
48/** ************************************************************************************************
49 * This abstract class represents a plug-in for the TextLogger class which converts the list
50 * of logables into a textual representation.
51 * \see StandardConverter for further information.
52 **************************************************************************************************/
54{
55 public:
56 /** ****************************************************************************************
57 * Destructs an object of this class.
58 ******************************************************************************************/
59 virtual ~ObjectConverter() {}
60
61 /** ****************************************************************************************
62 * The conversion method.
63 * @param target An AString that takes the result.
64 * @param logables The objects to convert.
65 ******************************************************************************************/
66 virtual void ConvertObjects( AString& target, Boxes& logables ) =0;
67
68 /** ****************************************************************************************
69 * If this converter uses an \alib{strings::util;AutoSizes} object, this method returns
70 * such object.
71 * @return The auto sizes used, \c nullptr if not applicable.
72 ******************************************************************************************/
73 virtual AutoSizes* GetAutoSizes() =0;
74
75 /** ****************************************************************************************
76 * If this converter uses an \alib{strings::util;AutoSizes} object, values of this field
77 * are reset.
78 ******************************************************************************************/
79 virtual void ResetAutoSizes() =0;
80};
81
82/** ************************************************************************************************
83 * Implements the interface
84 * \ref alib::lox::detail::textlogger::ObjectConverter "ObjectConverter". Class
85 * \ref alib::lox::detail::textlogger::TextLogger "TextLogger" creates an instance of this type in
86 * the moment no other (custom) type was set prior to the first log statement.
87 *
88 * This implementation uses
89 * two specialisations of class
90 * \alib{lang::format;Formatter} to format the given logables to a textual
91 * representation. The formatters (and their sequence!) are:
92 *
93 * 1. \alib{lang::format;FormatterPythonStyle;FormatterPythonStyle}
94 * 2. \alib{lang::format;FormatterJavaStyle;FormatterJavaStyle}
95 *
96 * This way, standard text logging supports format strings in Python style as well as in Java style.
97 **************************************************************************************************/
99{
100 public:
101 /**
102 * A list of formatters used to "convert" logables to strings.
103 * By default, each entry contains a concatenated pair of formatters of types
104 * \alib{lang::format;FormatterPythonStyle;FormatterPythonStyle} and
105 * \alib{lang::format;FormatterJavaStyle;FormatterJavaStyle} are added in the
106 * constructor of this class.
107 *
108 * A vector of formatter is needed to support recursive log calls.
109 * If recursion occurs during logging (aka the conversion of a logable triggers another
110 * logging operation), necessary formatters are created on the fly, respectively re-used
111 * from previous recursions.
112 * Their settings are cloned to those of the main formatters
113 * using \alib{lang::format;Formatter::CloneSettings}.
114 *
115 * The formatters created internally are set to
116 * \alib{threads;ThreadLock::SetSafeness;unsafe locking mode} (locking is switched-off).
117 * This is a small optimization and allowed due to the fact that class \b Lox is already
118 * thread-safe.
119 *
120 * To use different formatters, it is recommended to implement a different converter
121 * type, instead of "patching" the linked and recursive formatters found in this vector.
122 */
123 std::vector<Formatter*> Formatters;
124
125
126 protected:
127 /** A counter to detect recursive calls. */
129
130 public:
131
132 /** ****************************************************************************************
133 * Constructor.
134 ******************************************************************************************/
137
138 /** ****************************************************************************************
139 * Virtual destructor.
140 ******************************************************************************************/
142 virtual ~StandardConverter() override;
143
144 /** ****************************************************************************************
145 * The conversion method.
146 * Passes \p{target} and \p{logables} to the #Formatters.
147 * @param target An AString that takes the result.
148 * @param logables The objects to convert.
149 ******************************************************************************************/
151 virtual void ConvertObjects( AString& target, Boxes& logables ) override;
152
153 /** ****************************************************************************************
154 * Checks if the first formatter in #Formatters is of type
155 * \alib{lang::format;FormatterPythonStyle}. If so, its \b AutoSizes member is returned.
156 * If not, the method returns \c nullptr.
157 * @return The auto sizes object of the main formatter.
158 ******************************************************************************************/
160 virtual AutoSizes* GetAutoSizes() override;
161
162 /** ****************************************************************************************
163 * Resets automatically widened tab stops and field widths of this converter.
164 ******************************************************************************************/
166 virtual void ResetAutoSizes() override;
167};
168
169
170/** ************************************************************************************************
171 * This class is a sort of plug-in for the TextLogger class. Its purpose is to assemble the meta
172 * information of each log line (things like timestamps, thread information, verbosity and domain, etc.).
173 *
174 * To manipulate the meta information log output, three options exist:
175 * - by just changing the #Format string (at run-time).
176 * - by creating a derived class that introduces a new version of method #processVariable() to handle
177 * one or more format variable differently or to introduce new variables.
178 * - by creating a derived class that introduces a new version of method #Write() to
179 * completely control the meta information output.
180 **************************************************************************************************/
182{
183 // #############################################################################################
184 // Public fields
185 // #############################################################################################
186 public:
187 /**
188 * The line format specifies the (automated) log output that is prepended to each log line before
189 * the log message itself. This format string can be changed after the creation
190 * of a \ref TextLogger.
191 *
192 * The string supports replacement variables that begin with a % sign
193 * - %SP: The full path of the source file
194 * - %Sp: The trimmed path of the source file
195 * - %SF: The caller's source file name
196 * - %Sf: The caller's source file name without extension
197 * - %SL: The line number in the source file
198 * - %SM: The method name
199 *
200 * - %TD: The date the log call was invoked
201 * - %TT: Time of day the log call was invoked
202 * - %TC: Time elapsed since the Logger was created or its timer was reset
203 * - %TL: Time elapsed since the last log call
204 *
205 * - %tN: Thread name
206 * - %tI: Thread ID
207 * - %V: The verbosity. This is replaced by the corresponding strings found in fields
208 * #VerbosityError, #VerbosityWarning, #VerbosityInfo and #VerbosityVerbose.
209 * - %D: Log domain
210 * - %#: The log call counter (like a line counter, but counting multi lines as one)
211 * - %An: An auto-adjusted tabulator. This grows whenever it needs, but never shrinks. The
212 * optional integer number n specifies how much extra space is added when tab is adjusted.
213 * Setting this to a higher value avoids too many adjustments at the beginning of a log session.
214 * - %LG: The name of the \e Logger. This might be useful if multiple loggers write to the same
215 * output stream (e.g. Console).
216 * - %LX: The name of the \e Lox.
217 * - %P: The name of the process / application.
218 *
219 * Defaults to
220 * \code "%Sp/%SF(%SL):%A5%SM() %A5[%TC +%TL][%tN]%V[%D]%A1(%#): " \endcode
221 *
222 * If debug logging as well as release logging has scope information disabled
223 * (see \ref ALOX_DBG_LOG_CI and \ref ALOX_REL_LOG_CI), then it defaults to:
224 * <c>"[%TC +%TL][%tN]%V[%D]%A1(%#): "</c>
225 *
226 * \note
227 * The use of <c>%%TD</c> and <c>%%TT</c> may become problematic and ambiguous if the
228 * system clock is changed during a software run. Especially for long-running background
229 * software (daemons, servers, etc.), the software that uses \alox needs to provide
230 * a strategy of synchronizing the clock with field #DateConverter.<br>
231 * For some explanation of the problem see details of namespace #alib::time.
232 */
233 #if ALOX_DBG_LOG_CI || ALOX_REL_LOG_CI
234 AString Format { A_CHAR("%SF:%SL:%A3%SM %A3[%TC +%TL][%tN]%V[%D]%A1#%#: ")};
235 #else
236 AString Format { A_CHAR("[%TC +%TL][%tN]%V[%D]%A1#%#: ")};
237 #endif
238
239 /**
240 * If \c false, an one-time warning (using \ref ALIB_WARNING) will be issued if the format
241 * string is illegal. With each warning, the flag is set to \c true to omit further
242 * warnings.
243 */
244 bool FormatWarningOnce= false;
245
246
247 /** The replacement for variable \c %%V in field #Format if \e Verbosity is \c Error. */
249
250 /** The replacement for variable \c %%V in field #Format if \e Verbosity is \c Warning. */
252
253 /** The replacement for variable \c %%V in field #Format if \e Verbosity is \c Info. */
255
256 /** The replacement for variable \c %%V in field #Format if \e Verbosity is \c Verbose. */
258
259 /** Format string for the output of the log date. For more information, see
260 "Standard Date and Time Format Strings" in .NET StringBuilder.AppendFormat(). */
261 String32 DateFormat = A_CHAR("yyyy-MM-dd");
262
263 /** Format string for the output of the time of day. For more information, see
264 "Standard Date and Time Format Strings" in .NET StringBuilder.AppendFormat(). */
266
267 /** The word "Days" the out put of time elapsed (if longer than a day). */
269
270 /** Minimum time difference to log in nanoseconds. Below that #TimeDiffNone is written. */
271 int64_t TimeDiffMinimum =1000L;
272
273 /** Output for time difference if below reasonable (measurable) minimum defined in #TimeDiffMinimum. */
275
276 /** Entity nanoseconds for time difference outputs below 1000 microsecond. */
278
279 /** Entity microseconds for time difference outputs below 1000 microseconds. */
280 String16 TimeDiffMicros = A_CHAR(" \u00B5s"); // greek 'm' letter
281
282 /** Entity milliseconds for time difference outputs below 1000 milliseconds. */
284
285 /** Format for time difference outputs between 10s and 99.9s. */
287
288 /** Format for time difference outputs between 100s and 60 min. */
290
291 /** Format for time difference outputs between 1h and 24h. */
293
294 /** Format for time difference outputs of more than a day. */
296
297 /** Replacement string if no source info is available. */
299
300 /** Replacement string if no source info is available. */
302
303 /** The minimum digits to write for the log number (if used in format string). */
305
306 /**
307 * The maximum time elapsed. Used to determine the width of the output when writing
308 * the elapsed time.
309 *
310 * This field will be read from the configuration variable
311 * \ref alxcvALOX_LOGGERNAME_MAX_ELAPSED_TIME when the \b %TextLogger that this object belongs
312 * to is attached to a \b %Lox and written back on removal.
313 */
314 Ticks::Duration MaxElapsedTime;
315
316
317 /**
318 * This field is used to convert the steady and monotonic clock values provided with
319 * \alox{detail,ScopeInfo::GetTimeStamp} into human readable, calendrical values in the
320 * moment, field #Format contains tokens <c>%%TD</c> and/or <c>%%TT</c>.
321 *
322 * This may become problematic and ambiguous if the system clock is changed during a
323 * software run. Especially for long-running background software (daemons, servers, etc.),
324 * the software that uses \alox needs to provide a strategy of synchronizing this converter
325 * with the system clock.
326 *
327 * A simple strategy is to just periodically invoke \alib{time;TickConverter::SyncClocks},
328 * for example once a second.
329 *
330 * For some explanation of the problem see details of namespace #alib::time.
331 */
333
334 // #############################################################################################
335 // Internal fields
336 // #############################################################################################
337 protected:
338
339 /** A singleton calendar time object shared between different format variables during one
340 * invocation. */
342
343 // #############################################################################################
344 // Constructor/Destructor
345 // #############################################################################################
346 public:
347 /** ****************************************************************************************
348 * Constructor.
349 ******************************************************************************************/
351
352 /** ****************************************************************************************
353 * Virtual destructor.
354 ******************************************************************************************/
355 virtual ~MetaInfo() {}
356
357 // #############################################################################################
358 // Public interface
359 // #############################################################################################
360 public:
361
362 /** ****************************************************************************************
363 * Parses the #Format string and logs meta information into the log buffer. For each
364 * variable found, method #processVariable is invoked. Hence, to add new variables,
365 * the latter method can be overwritten by descendants. Overwriting this method is
366 * recommended for formatter classes that do not rely on format strings.
367 * @param logger The logger that we are embedded in.
368 * @param buffer The buffer to write meta information into.
369 * @param domain The <em>Log Domain</em>.
370 * @param verbosity The verbosity.
371 * @param scope Information about the scope of the <em>Log Statement</em>..
372 ******************************************************************************************/
374 virtual void Write( TextLogger& logger,
375 AString& buffer,
376 detail::Domain& domain,
377 Verbosity verbosity,
378 ScopeInfo& scope );
379
380 // #############################################################################################
381 // Internals
382 // #############################################################################################
383 protected:
384
385 /** ****************************************************************************************
386 * Processes the next command found in the format string, by writing formatted information
387 * into the given buffer.
388 * The given
389 * \alib{strings;TSubstring;Substring} holds the next command.
390 * When method the returns, the command is cut from the front.
391 *
392 * @param logger The logger that we are embedded in.
393 * @param domain The <em>Log Domain</em>.
394 * @param verbosity The verbosity. This has been checked to be active already on this
395 * stage and is provided to be able to be logged out only.
396 * @param scope Information about the scope of the <em>Log Statement</em>..
397 * @param dest The buffer to write meta information into.
398 * @param variable The variable to read (may have more characters appended)
399 ******************************************************************************************/
401 virtual void processVariable( TextLogger& logger,
402 detail::Domain& domain,
403 Verbosity verbosity,
404 ScopeInfo& scope,
405 AString& dest,
406 Substring& variable );
407
408 /** ****************************************************************************************
409 * Helper function that logs a time given difference into the given buffer in a human readable
410 * format. Works from nanoseconds seconds to days.
411 *
412 * @param buffer The buffer to write the time difference representation into.
413 * @param diffNanos The time difference to write in nanoseconds.
414 ******************************************************************************************/
416 virtual void writeTimeDiff ( AString& buffer, int64_t diffNanos );
417}; // class
418
419
420
421/** ************************************************************************************************
422 * This class is a still abstract implementation of class Logger which is used as the super class
423 * for all textual Logger implementations within \alox, e.g. ConsoleLogger.
424 *
425 * The class uses a helper class to generate the textual representation of the meta information
426 * of a log call.
427 * This helper can be extended and replaced in #MetaInfo to modify the behavior of TextLogger.
428 *
429 * The final log message is then passed to the abstract method #logText.
430 * Hence, custom Logger classes that inherited from this class instead of directly from class
431 * #Logger, need to implement #logText instead of implementing #Log.
432 *
433 * Class TextLogger supports multi line log outputs. Such multi line log outputs can be configured to
434 * be logged in different ways. See #MultiLineMsgMode for more information.
435 **************************************************************************************************/
436class TextLogger : public Logger
437{
438
439 // #############################################################################################
440 // Internal fields
441 // #############################################################################################
442 protected:
443
444 /** The internal log Buffer. */
446
447 /** The buffers for converting the logables. */
449
450 /** Denotes whether this logger writes to the <em>standard output streams</em>. If so,
451 \alib{threads;SmartLock::StdOutputStreams} is acquired on logging. */
453
454 #if ALIB_THREADS
455 /** Used to avoid repeated registration with \alib <em>standard output stream</em> lockers
456 when attached to multiple instances of class \b Lox. */
458 #endif
459
460 /**
461 * A list of pairs of strings. Within each log message, the first string of a pair is
462 * searched and replaced by the second string. Very simple, but useful in some cases.
463 */
464 std::vector<AString> replacements;
465
466 public: // public only to allow being resourced
467 /** Denotes the use of light vs dark colors. Used with descendant classes only. */
469 {
470 Auto, ///< Automatic
471 Never, ///< Never use light colors
472 Foreground, ///< Use light colors for foreground
473 Background ///< Use light colors for background
474 };
475
476 // #############################################################################################
477 // Public fields
478 // #############################################################################################
479 public:
480 /**
481 * A helper object to get textual representation of logable objects.
482 * If no converter is set when this logger is attached to a lox, a converter of type
483 * \alib{lox::detail::textlogger;StandardConverter} is created and used.
484 * Custom loggers might create their own, custom converter objects here.
485 * In the destructor of this class, the current object converter will be deleted.
486 *
487 * To extend class \b %TextLogger to support logging custom objects, custom converters can
488 * set. The preferred alternative is however, to make custom types be formattable
489 * by formatter classes used with \b %StandardConverter.
490 */
492
493 /**
494 * A helper object to format log objects into textual representations. This class incorporates
495 * a format string that defines the meta information in the log output. Furthermore, to extend
496 * TextLogger, this object can be replaced by custom implementations of it.
497 */
499
500 /**
501 * Characters written after each <em>Log Statement</em>.
502 * This may be used for example to reset colors and styles.
503 * Note, that with multi-line <em>Log Statements</em>, the contents of this field is \b not
504 * written at the end of each line, but only at the end of the last line.
505 * To define characters that are written after each line of a multi-line
506 * <em>Log Statement</em>, field #FmtMultiLineSuffix.
507 *
508 * Defaults to empty string.
509 */
511
512 /**
513 * Holds a list of values for auto tab positions and field sizes.
514 * For each requested value, a corresponding array field is created on the fly.
515 * If the format string get's changed and different (new) auto values should be used, then
516 * this field should be reset after setting the new format string.
517 * The other way round, it is also possible to preset set minimum values for tabs and field
518 * sizes and hence avoid the columns growing during the lifetime of the Logger.
519 *
520 * This field will be read from configuration variable \ref alxcvALOX_LOGGERNAME_AUTO_SIZES
521 * when this \b %TextLogger is attached to a \b %Lox and written back on removal.
522 */
524
525 /**
526 * Determines if multi line messages should be split into different log lines. Possible
527 * values are:
528 *
529 * - 0: No line split is performed, delimiters can be replaced by readable delimiters
530 * (depending on setting of #MultiLineDelimiter and # MultiLineDelimiterRepl).
531 *
532 * - 1: Each log line contains all meta information
533 *
534 * - 2: Starting with second log line, meta information is replaced by blanks (default)
535 *
536 * - 3: The headline #FmtMultiLineMsgHeadline is logged and all lines of the multi line
537 * text are logged at position zero (without further meta information)
538 *
539 * - 4: Just the multi line text is logged, starting at column zero (no meta information
540 * is logged)
541 *
542 * \note In modes 3 and 4, no ESC::EOMETA is included at the beginning of the message.
543 * Loggers that need such info, have to implement method #notifyMultiLineOp.
544 */
546
547 /**
548 * This is the string interpreted as line delimiter within log messages. If \e nulled, then
549 * <c>'\\n'</c>, <c>'\\r'</c> or <c>'\\r\\n'</c> is recognized.<br>
550 * Important: Can be set to an empty string, to stop any multi line processing of
551 * \b %TextLogger, even the replacements of the delimiter character.
552 */
554
555 /**
556 * This is the readable (!) separator string, for logging out multi line messages into a
557 * single line (#MultiLineMsgMode==0).
558 * Defaults to "\\r".
559 */
561
562 /**
563 * Headline for multi line messages (depending on #MultiLineMsgMode) .
564 * Defaults to "ALox: Multi line message follows: "
565 */
566 String64 FmtMultiLineMsgHeadline= A_CHAR("ALox: Multi line message follows: ");
567
568 /**
569 * Prefix for multi line messages. This is also used if multi line messages logging is
570 * switched off (MultiLineMsgMode == 0) but replacing of a set MultiLineDelimiter takes
571 * place.
572 * Defaults to ">> ".
573 */
575
576 /**
577 * Suffix for multi line messages. This is also used if multi line messages logging is
578 * switched off (MultiLineMsgMode == 0) and replacing of a set #MultiLineDelimiter
579 * takes place.<br>
580 * Note that at the end of the last line, in addition #FmtMsgSuffix is added.<br>
581 * Defaults to "".
582 */
584
585 // #############################################################################################
586 // protected Constructor/ public destructor
587 // #############################################################################################
588 protected:
589 /** ****************************************************************************************
590 * Constructs a TextLogger.
591 * Reads the format variable for the meta information from the configuration. The
592 * variable name is created from the \e Logger name and the suffix <c>'_FORMAT'</c>
593 * @param pName The name of the \e Logger.
594 * @param typeName The type of the \e Logger.
595 * @param pUsesStdStreams Denotes whether this logger writes to the
596 * <em>standard output streams</em>.
597 ******************************************************************************************/
598 ALIB_API explicit TextLogger( const NString& pName, const NString& typeName,
599 bool pUsesStdStreams );
600
601 /** ****************************************************************************************
602 * Destructs a TextLogger.
603 ******************************************************************************************/
604 public:
605 ALIB_API virtual ~TextLogger() override;
606
607 // #############################################################################################
608 // Overriding parent's virtual, empty method AcknowledgeLox()
609 // #############################################################################################
610
611 /** ****************************************************************************************
612 * Configuration variables are read within this method and created with
613 * default values, in the case they do not exist, yet. The variables read and optionally
614 * created are:
615 * - \b ALox::AUTO_SIZES
616 * - \b ALox::FORMAT
617 * - \b ALox::FORMAT_DATE_TIME
618 * - \b ALox::FORMAT_MULTILINE
619 * - \b ALox::FORMAT_TIME_DIFF
620 * - \b ALox::MAX_ELAPSED_TIME
621 * - \b ALox::REPLACEMENTS
622 *
623 * Configuration variables are \ref alib_alox_cfgvars "documented here".
624 *
625 * Furthermore, invokes grand-parent's method \alib{threads;SmartLock::AddAcquirer},
626 * respectively \alib{threads;SmartLock::RemoveAcquirer} and in addition,
627 * if field #usesStdStreams is set, registers with
628 * \alib{threads;SmartLock::StdOutputStreams}.
629 *
630 * @param lox The \b %Lox to acknowledge insertion or removal
631 * @param op The operation. Either \b ContainerOp::Insert or \b ContainerOp::Remove.
632 ******************************************************************************************/
634 virtual void AcknowledgeLox( LoxImpl* lox, lang::ContainerOp op ) override;
635
636
637 // #############################################################################################
638 // Abstract methods introduced
639 // #############################################################################################
640 protected:
641 /** ****************************************************************************************
642 * This abstract method introduced by this class "replaces" the abstract method #Log
643 * of parent class Logger which this class implements. In other words, descendants of this
644 * class need to override this method instead of \b %Log. This class %TextLogger is
645 * responsible for generating meta information, doing text replacements, handle multi-line
646 * messages, etc. and provides the textual representation of the whole log contents
647 * to descendants using this method.
648 *
649 * @param domain The <em>Log Domain</em>.
650 * @param verbosity The verbosity. This has been checked to be active already on this
651 * stage and is provided to be able to be logged out only.
652 * @param msg The log message.
653 * @param scope Information about the scope of the <em>Log Statement</em>.
654 * @param lineNumber The line number of a multi-line message, starting with 0.
655 * For single line messages this is -1.
656 ******************************************************************************************/
657 virtual void logText( detail::Domain& domain,
658 Verbosity verbosity,
659 AString& msg,
660 detail::ScopeInfo& scope,
661 int lineNumber ) =0;
662
663 /** ****************************************************************************************
664 * Abstract method to be implemented by descendants. This message is called only when
665 * multi-line messages are logged. It is called exactly once before a series of #logText
666 * calls of a multi-line message and exactly once after such series.<br>
667 * This is useful if the writing of text includes the acquisition of system resources
668 * (e.g. opening a file).
669 *
670 * @param phase Indicates the beginning or end of a multi-line operation.
671 ******************************************************************************************/
672 virtual void notifyMultiLineOp( lang::Phase phase ) =0;
673
674 // #############################################################################################
675 // Abstract method implementations
676 // #############################################################################################
677 public:
678 /** ****************************************************************************************
679 * This is the implementation of the abstract method inherited from class Logger
680 * that executes a log.<br>
681 * This class implements this method and but exposes the new abstract method #logText.
682 * This mechanism allows this class to do various things that are standard to Loggers
683 * of type TextLogger. For example, meta information of the log invocation is formatted
684 * and string replacements are performed. This way, descendants of this class will consume
685 * a ready to use log buffer with all meta information and contents of all objects to be
686 * included and their primary obligation is to copy the content into a corresponding
687 * output stream.
688 *
689 * @param domain The <em>Log Domain</em>.
690 * @param verbosity The verbosity.
691 * @param logables The list of objects to log.
692 * @param scope Information about the scope of the <em>Log Statement</em>..
693 ******************************************************************************************/
695 virtual void Log( Domain& domain, Verbosity verbosity, Boxes& logables,
696 ScopeInfo& scope) override;
697
698 // #############################################################################################
699 // Public interface
700 // #############################################################################################
701 public:
702 /** ****************************************************************************************
703 * Adds the given pair of replacement strings. If searched string already exists, the
704 * current replacement string gets replaced. If the replacement string is \c nullptr,
705 * nothing is set and a previously set replacement definition becomes unset.
706 * @param searched The string to be searched.
707 * @param replacement The replacement string. If this equals 'nullptr' a previously set
708 * replacement will be unset.
709 ******************************************************************************************/
711 virtual void SetReplacement( const String& searched, const String& replacement );
712
713 /** ****************************************************************************************
714 * Removes all pairs of searched strings and their replacement value.
715 ******************************************************************************************/
717 virtual void ClearReplacements();
718
719 /** ****************************************************************************************
720 * Resets automatically widened tab stops and field widths of this logger by calling
721 * \alib{lox::detail::textlogger::StandardConverter;ResetAutoSizes} on field #Converter.
722 *
723 * \note The sizes affected are the ones used to format the custom log output, not
724 * the ones uses for the meta information. To reset the auto-sizes of the meta
725 * information, invoke \alib{strings::util;AutoSizes::Reset} on field #AutoSizes.
726 ******************************************************************************************/
728 virtual void ResetAutoSizes();
729
730
731}; // class TextLogger
732
733}}} // namespace alib[::lox::detail::textlogger]
734
735/// Type alias in namespace \b alib.
737
738} // namespace [alib]
739
742
743
744#endif // HPP_ALOX_DETAIL_TEXTLOGGER_TEXTLOGGER
virtual ALIB_API void processVariable(TextLogger &logger, detail::Domain &domain, Verbosity verbosity, ScopeInfo &scope, AString &dest, Substring &variable)
virtual ALIB_API void writeTimeDiff(AString &buffer, int64_t diffNanos)
virtual ALIB_API void Write(TextLogger &logger, AString &buffer, detail::Domain &domain, Verbosity verbosity, ScopeInfo &scope)
lang::system::CalendarDateTime callerDateTime
virtual void ConvertObjects(AString &target, Boxes &logables)=0
virtual ALIB_API void ResetAutoSizes() override
virtual ALIB_API AutoSizes * GetAutoSizes() override
virtual ALIB_API void ConvertObjects(AString &target, Boxes &logables) override
virtual ALIB_API ~StandardConverter() override
virtual ALIB_API void ClearReplacements()
virtual ALIB_API void AcknowledgeLox(LoxImpl *lox, lang::ContainerOp op) override
virtual void notifyMultiLineOp(lang::Phase phase)=0
virtual ALIB_API void SetReplacement(const String &searched, const String &replacement)
virtual void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber)=0
virtual ALIB_API ~TextLogger() override
#define A_CHAR(STR)
#define ALIB_ENUMS_ASSIGN_RECORD(TEnum, TRecord)
Definition records.hpp:752
#define ALIB_API
Definition alib.hpp:538
Definition alib.cpp:57
lox::Log Log
Type alias in namespace alib.
Definition log.inl:158
lox::detail::textlogger::TextLogger TextLogger
Type alias in namespace alib.