ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
memorylogger.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//==================================================================================================
8ALIB_EXPORT namespace alib { namespace lox { namespace loggers {
9
10//==================================================================================================
11/// A logger that logs all messages to an in-memory buffer of type AString. The name of the \e Logger
12/// defaults to "MEMORY".
13//==================================================================================================
15{
16 //################################################################################################
17 // public fields
18 //################################################################################################
19 public:
20 /// The logging Buffer. This can be accessed publicly and hence used quite freely.
21 /// Especially, the whole log can easily be cleared using
22 /// \alib{strings;TAString::Reset;AString::Reset}.
23 /// In multithreaded environments, \c Lox interface's mutex should be acquired
24 /// before accessing this buffer. The initial size of the buffer is 8kb.
26
27 /// If this field is set to \c true (which is the default), the effective length of the
28 /// messages when converted to wide character strings are taken into account.
29 ///
30 /// Switching this off increases the overall logging performance (especially when logging
31 /// into memory) significantly.
33
34 //################################################################################################
35 // Constructor/destructor
36 //################################################################################################
37 public:
38 /// Creates a MemoryLogger with the given name.
39 /// @param name (Optional) The name of the \e Logger. Defaults to "MEMORY".
40 /// @param pruneESCSequences (Optional) Sets the member \ref PruneESCSequences.
41 /// Defaults to \c true.
42 /// @param useWStringLengthForTabAdjustments (Optional) Sets the member
43 /// \ref UseWStringLengthForTabAdjustments.
44 /// Defaults to \c true.
45 explicit MemoryLogger( const NString& name = nullptr,
46 bool pruneESCSequences = true,
47 bool useWStringLengthForTabAdjustments= true )
48 : PlainTextLogger( name, "MEMORY" ) {
49 MemoryLog.SetBuffer( 8092 );
50 PruneESCSequences = pruneESCSequences;
51 UseWStringLengthForTabAdjustments= useWStringLengthForTabAdjustments;
52 }
53
54
55 /// Destructs a MemoryLogger
56 virtual ~MemoryLogger() override {}
57
58 //################################################################################################
59 // Abstract method implementations
60 //################################################################################################
61 protected:
62 /// Start a new log line. Appends a new-line character sequence to previously logged lines.
63 ///
64 /// @param phase Indicates the beginning or end of a log line.
65 /// @return Always returns true.
66 virtual bool notifyPlainTextLogOp(lang::Phase phase) override {
67 // append new line if buffer has already lines stored
68 if ( phase == lang::Phase::Begin && MemoryLog.IsNotEmpty() )
69 MemoryLog.NewLine();
70 return true;
71 }
72
73 /// Write the given region of the given AString to the destination buffer.
74 ///
75 /// @param buffer The string to write a portion of.
76 /// @param start The start of the portion in \p{buffer} to write out.
77 /// @param length The length of the portion in \p{buffer} to write out.
78 /// @return The number of characters written, -1 on error.
79 virtual integer logPlainTextPart( const String& buffer,
80 integer start, integer length ) override {
81 MemoryLog._<NC>( buffer, start, length );
83 ? buffer.Substring<NC>( start, length ).WStringLength()
84 : length;
85 }
86
87 /// Empty implementation, not needed for this class
88 virtual void notifyMultiLineOp( lang::Phase ) override {}
89
90}; // class MemoryLogger
91
92}} // namespace alib[::lox::loggers]
93
94/// Type alias in namespace \b alib.
96
97} // namespace [alib]
virtual void notifyMultiLineOp(lang::Phase) override
Empty implementation, not needed for this class.
virtual ~MemoryLogger() override
Destructs a MemoryLogger.
virtual integer logPlainTextPart(const String &buffer, integer start, integer length) override
virtual bool notifyPlainTextLogOp(lang::Phase phase) override
MemoryLogger(const NString &name=nullptr, bool pruneESCSequences=true, bool useWStringLengthForTabAdjustments=true)
PlainTextLogger(const NString &name, const NString &typeName)
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
Definition string.inl:384
#define ALIB_EXPORT
Definition alib.inl:497
Phase
Denotes a phase, e.g.,of a transaction.
@ Begin
The start of a transaction.
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
lox::loggers::MemoryLogger MemoryLogger
Type alias in namespace alib.