ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
plaintextlogger.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_PLAINTEXTLOGGER
9#define HPP_ALOX_DETAIL_TEXTLOGGER_PLAINTEXTLOGGER 1
10
11
12#if !defined (HPP_ALOX_DETAIL_TEXTLOGGER_TEXTLOGGER)
14#endif
15
16// #################################################################################################
17// forward declarations
18// #################################################################################################
19
20namespace alib { namespace lox { namespace detail { namespace textlogger{
21
22/** ************************************************************************************************
23 * A text logger that either removes or ignores (just writes through) \alox ESC sequences.
24 * Implements abstract method #logText and introduces two new abstract methods
25 * #logSubstring and #notifyLogOp.
26 **************************************************************************************************/
28{
29 // #############################################################################################
30 // public fields
31 // #############################################################################################
32 public:
33 /**
34 * If this field is set to \c true (the default), all \ref alib::lox::ESC "ESC" color and
35 * style codes get removed when logging into this Logger. \c ESC::TAB is processed.
36 *
37 * It might be useful, to set this to false, e.g. in the case, the contents of the
38 * Logger is (later) written into a different logger (e.g. as a multi line message)
39 * which is capable of interpreting the escape sequences of class ESC.
40 */
41 bool PruneESCSequences = true;
42
43 // #############################################################################################
44 // Constructor/destructor
45 // #############################################################################################
46 protected:
47 /** ****************************************************************************************
48 * Creates a PlainTextLogger
49 * @param name The name of the \e Logger. If empty, it defaults to the type name.
50 * @param typeName The type of the \e Logger.
51 * @param pUsesStdStreams Denotes whether this logger writes to the
52 * <em>standard output streams</em>.
53 ******************************************************************************************/
54 explicit PlainTextLogger( const NString& name, const NString& typeName, bool pUsesStdStreams )
55 : TextLogger( name, typeName, pUsesStdStreams )
56 {}
57
58 /** ****************************************************************************************
59 * Destructs a MemoryLogger
60 ******************************************************************************************/
61 virtual ~PlainTextLogger() override
62 {}
63
64 // #############################################################################################
65 // Abstract methods introduced
66 // #############################################################################################
67 protected:
68 /** ****************************************************************************************
69 * Abstract method to be implemented by descendants. This method is called when a new
70 * log message is started. It is called exactly once before a series of logSubstring()
71 * calls and exactly once after such series. If either the start or one of the calls
72 * to #logSubstring returns \c false, the second invocation that would indicate the end of
73 * a log message is omitted.
74 *
75 * Implementing this method allows the acquisition of system resources
76 * (e.g. opening a file).
77 *
78 * @param phase Indicates the beginning or end of a log line.
79 * @return If \c false is returned, the log line is aborted without an invocation of
80 * \ref notifyLogOp "notifyLogOp(Phase::End)".
81 ******************************************************************************************/
82 virtual bool notifyLogOp( lang::Phase phase ) = 0;
83
84 /** ****************************************************************************************
85 * Abstract method to be implemented by descendants. Has to write the given region of
86 * the given string to the destination.
87 * Has to return the number of characters written, which might be different from the
88 * region length requested, e.g. in case of character set conversions.
89 *
90 * If an error occurs, \c -1 can be returned to indicate that the current log should be
91 * aborted. In this case, no invocation of \ref notifyLogOp "notifyLogOp(Phase::End)"
92 * will be performed.
93 *
94 * @param buffer The string to write a portion of.
95 * @param start The start of the portion in \p{buffer} to write out.
96 * @param length The length of the portion in \p{buffer} to write out.
97 * @return The number of characters written, -1 on error.
98 ******************************************************************************************/
99 virtual integer logSubstring( const String& buffer, integer start, integer length ) = 0;
100
101
102 // #############################################################################################
103 // Abstract method implementations
104 // #############################################################################################
105 protected:
106 /** ****************************************************************************************
107 * The implementation of the abstract method of parent class TextLogger.
108 * Loops over the log text, removes or ignores ESC sequences (all but ESC.TAB) and invokes
109 * abstract methods of descendants as follows:
110 * - \ref notifyLogOp "notifyLogOp(true)"
111 * - #logSubstring()
112 * - ...
113 * - \ref notifyLogOp "notifyLogOp(Phase::End)"
114 *
115 * @param domain The <em>Log Domain</em>.
116 * @param verbosity The verbosity. This has been checked to be active already on this
117 * stage and is provided to be able to be logged out only.
118 * @param msg The log message.
119 * @param scope Information about the scope of the <em>Log Statement</em>..
120 * @param lineNumber The line number of a multi-line message, starting with 0. For
121 * single line messages this is -1.
122 ******************************************************************************************/
124 virtual void logText( detail::Domain& domain, Verbosity verbosity,
125 AString& msg,
126 detail::ScopeInfo& scope, int lineNumber ) override;
127}; // class PlainTextLogger
128
129}}}} // namespace [alib::lox::detail::textlogger]
130
131#endif // HPP_ALOX_DETAIL_TEXTLOGGER_PLAINTEXTLOGGER
virtual integer logSubstring(const String &buffer, integer start, integer length)=0
PlainTextLogger(const NString &name, const NString &typeName, bool pUsesStdStreams)
virtual bool notifyLogOp(lang::Phase phase)=0
virtual ALIB_API void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber) override
#define ALIB_API
Definition alib.hpp:538
Definition alib.cpp:57
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286