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