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