ALib C++ Library
Library Version: 2511 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/// #logPlainTextPart and #notifyPlainTextLogOp.
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 are (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.
28
29 //################################################################################################
30 // Constructor/destructor
31 //################################################################################################
32 protected:
33 /// Creates a PlainTextLogger
34 /// @param name The name of the \e Logger. If empty, it defaults to the type name.
35 /// @param typeName The type of the \e Logger.
36 explicit PlainTextLogger( const NString& name, const NString& typeName)
37 : TextLogger( name, typeName ) {}
38
39 /// Destructs a MemoryLogger
40 virtual ~PlainTextLogger() override {}
41
42 //################################################################################################
43 // Abstract methods introduced
44 //################################################################################################
45 protected:
46 /// Abstract method to be implemented by descendants. This method is called when a new
47 /// log message is started. It is called exactly once before a series of #logPlainTextPart
48 /// calls and exactly once after such series. If either the start or one of the calls
49 /// to #logPlainTextPart returns a negative number, the second invocation that would
50 /// indicate the end of a log message is omitted.
51 ///
52 /// Implementing this method allows the acquisition of system resources
53 /// (e.g., opening a file).
54 ///
55 /// @param phase Indicates the beginning or end of a log line.
56 /// @return If \c false is returned, the log line is aborted without an invocation of
57 /// \ref notifyPlainTextLogOp "notifyPlainTextLogOp(Phase::End)".
58 virtual bool notifyPlainTextLogOp( lang::Phase phase ) =0;
59
60 /// Abstract method to be implemented by descendants. Has to write the given region of
61 /// the given string to the destination.
62 /// Has to return the number of characters written, which might be different from the
63 /// region length requested, e.g., in case of character set conversions.
64 ///
65 /// If an error occurs, \c -1 can be returned to indicate that the current log should be
66 /// aborted. In this case, no invocation of
67 /// \ref notifyPlainTextLogOp "notifyPlainTextLogOp(Phase::End)" will be performed.
68 ///
69 /// @param buffer The string to write a portion of.
70 /// @param start The start of the portion in \p{buffer} to write out.
71 /// @param length The length of the portion in \p{buffer} to write out.
72 /// @return The number of characters written, -1 on error.
73 virtual integer logPlainTextPart( const String& buffer, integer start, integer length ) =0;
74
75
76 //################################################################################################
77 // Abstract method implementations
78 //################################################################################################
79 protected:
80 /// The implementation of the abstract method of parent class TextLogger.
81 /// Loops over the log text, removes or ignores ESC sequences (all but ESC.TAB) and invokes
82 /// abstract methods of descendants as follows:
83 /// - \ref notifyPlainTextLogOp "notifyPlainTextLogOp(true)"
84 /// - #logPlainTextPart()
85 /// - ...
86 /// - \ref notifyPlainTextLogOp "notifyPlainTextLogOp(Phase::End)"
87 ///
88 /// @param domain The <em>Log Domain</em>.
89 /// @param verbosity The verbosity. This has been checked to be active already on this
90 /// stage and is provided to be able to be logged out only.
91 /// @param msg The log message.
92 /// @param scope Information about the scope of the <em>Log Statement</em>..
93 /// @param lineNumber The line number of a multi-line message, starting with 0. For
94 /// single line messages this is -1.
95 /// @param isRecursion If \c true, a recursive logging operation was detected. A logger might
96 /// use this information, for example, to prevent recursive acquisitions
97 /// of resources.
99 virtual void logText( detail::Domain& domain,
100 Verbosity verbosity,
101 AString& msg,
102 detail::ScopeInfo& scope,
103 int lineNumber,
104 bool isRecursion ) override;
105}; // class PlainTextLogger
106
107} // namespace [alib::lox::textlogger]
virtual ALIB_DLL void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber, bool isRecursion) override
virtual bool notifyPlainTextLogOp(lang::Phase phase)=0
virtual ~PlainTextLogger() override
Destructs a MemoryLogger.
PlainTextLogger(const NString &name, const NString &typeName)
virtual integer logPlainTextPart(const String &buffer, integer start, integer length)=0
ALIB_DLL TextLogger(const NString &pName, const NString &typeName)
#define ALIB_DLL
Definition alib.inl:503
#define ALIB_EXPORT
Definition alib.inl:497
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:2198
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189