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