ALib C++ Library
Library Version: 2510 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 as preferred.
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 // #############################################################################################
36 // Constructor/destructor
37 // #############################################################################################
38 public:
39 //==========================================================================================
40 /// Creates a MemoryLogger with the given name.
41 /// @param name (Optional) The name of the \e Logger. Defaults to "MEMORY".
42 /// @param pruneESCSequences (Optional) Sets the member \ref PruneESCSequences.
43 /// Defaults to \c true.
44 /// @param useWStringLengthForTabAdjustments (Optional) Sets the member
45 /// \ref UseWStringLengthForTabAdjustments.
46 /// Defaults to \c true.
47 //==========================================================================================
48 explicit MemoryLogger( const NString& name = nullptr,
49 bool pruneESCSequences = true,
50 bool useWStringLengthForTabAdjustments= true )
51 : PlainTextLogger( name, "MEMORY", false )
52 {
53 MemoryLog.SetBuffer( 8092 );
54 PruneESCSequences = pruneESCSequences;
55 UseWStringLengthForTabAdjustments= useWStringLengthForTabAdjustments;
56 }
57
58
59 //==========================================================================================
60 /// Destructs a MemoryLogger
61 //==========================================================================================
62 virtual ~MemoryLogger() override {}
63
64 // #############################################################################################
65 // Abstract method implementations
66 // #############################################################################################
67 protected:
68 //==========================================================================================
69 /// Start a new log line. Appends a new-line character sequence to previously logged lines.
70 ///
71 /// @param phase Indicates the beginning or end of a log line.
72 /// @return Always returns true.
73 //==========================================================================================
74 virtual bool notifyLogOp(lang::Phase phase) override
75 {
76 // append new line if buffer has already lines stored
77 if ( phase == lang::Phase::Begin && MemoryLog.IsNotEmpty() )
78 MemoryLog.NewLine();
79 return true;
80 }
81
82 //==========================================================================================
83 /// Write the given region of the given AString to the destination buffer.
84 ///
85 /// @param buffer The string to write a portion of.
86 /// @param start The start of the portion in \p{buffer} to write out.
87 /// @param length The length of the portion in \p{buffer} to write out.
88 /// @return The number of characters written, -1 on error.
89 //==========================================================================================
90 virtual integer logSubstring( const String& buffer,
91 integer start, integer length ) override
92 {
93 MemoryLog._<NC>( buffer, start, length );
95 ? buffer.Substring<NC>( start, length ).WStringLength()
96 : length;
97 }
98
99 //==========================================================================================
100 /// Empty implementation, not needed for this class
101 //==========================================================================================
102 virtual void notifyMultiLineOp( lang::Phase ) override {}
103
104}; // class MemoryLogger
105
106}} // namespace alib[::lox::loggers]
107
108/// Type alias in namespace \b alib.
110
111} // namespace [alib]
112
virtual void notifyMultiLineOp(lang::Phase) override
Empty implementation, not needed for this class.
virtual integer logSubstring(const String &buffer, integer start, integer length) override
virtual ~MemoryLogger() override
Destructs a MemoryLogger.
virtual bool notifyLogOp(lang::Phase phase) override
MemoryLogger(const NString &name=nullptr, bool pruneESCSequences=true, bool useWStringLengthForTabAdjustments=true)
PlainTextLogger(const NString &name, const NString &typeName, bool pUsesStdStreams)
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
Definition string.inl:386
#define ALIB_EXPORT
Definition alib.inl:488
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:2390
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
lox::loggers::MemoryLogger MemoryLogger
Type alias in namespace alib.