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