ALib C++ Library
Library Version: 2402 R1
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 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8
9#ifndef HPP_ALOX_MEMORY_LOGGER
10#define HPP_ALOX_MEMORY_LOGGER 1
11
12#if !defined (HPP_ALOX_DETAIL_TEXTLOGGER_PLAINTEXTLOGGER)
14#endif
15
16namespace alib { namespace lox { namespace loggers {
17
18/** ************************************************************************************************
19 * A logger that logs all messages to an in-memory buffer of type AString. The name of the \e Logger
20 * defaults to "MEMORY".
21 **************************************************************************************************/
23{
24 // #############################################################################################
25 // public fields
26 // #############################################################################################
27 public:
28 /**
29 * The logging Buffer. This can be accessed publicly and hence used as preferred.
30 * Especially, the whole log can easily be cleared using
31 * \alib{strings;TAString::Reset;AString::Reset}.
32 * In multi-threaded environments, \c Lox interface's mutex should be acquired
33 * before accessing this buffer. The initial size of the buffer is 8kb.
34 */
36
37 /**
38 * If this field is set to \c true (which is the default), the effective length of the
39 * messages when converted to wide character strings are taken into account.
40 *
41 * Switching this off increases the overall logging performance (especially when logging
42 * into memory) significantly.
43 */
45
46
47 // #############################################################################################
48 // Constructor/destructor
49 // #############################################################################################
50 public:
51 /** ****************************************************************************************
52 * Creates a MemoryLogger with the given name.
53 * @param name (Optional) The name of the \e Logger. Defaults to "MEMORY".
54 * @param pruneESCSequences (Optional) Sets the member \ref PruneESCSequences.
55 * Defaults to \c true.
56 * @param useWStringLengthForTabAdjustments (Optional) Sets the member
57 * \ref UseWStringLengthForTabAdjustments.
58 * Defaults to \c true.
59 ******************************************************************************************/
60 explicit MemoryLogger( const NString& name = nullptr,
61 bool pruneESCSequences = true,
62 bool useWStringLengthForTabAdjustments= true )
63 : PlainTextLogger( name, "MEMORY", false )
64 {
65 MemoryLog.SetBuffer( 8092 );
66 PruneESCSequences = pruneESCSequences;
67 UseWStringLengthForTabAdjustments= useWStringLengthForTabAdjustments;
68 }
69
70
71 /** ****************************************************************************************
72 * Destructs a MemoryLogger
73 ******************************************************************************************/
74 virtual ~MemoryLogger() override {}
75
76 // #############################################################################################
77 // Abstract method implementations
78 // #############################################################################################
79 protected:
80 /** ****************************************************************************************
81 * Start a new log line. Appends a new-line character sequence to previously logged lines.
82 *
83 * @param phase Indicates the beginning or end of a log line.
84 * @return Always returns true.
85 ******************************************************************************************/
86 virtual bool notifyLogOp(lang::Phase phase) override
87 {
88 // append new line if buffer has already lines stored
89 if ( phase == lang::Phase::Begin && MemoryLog.IsNotEmpty() )
91 return true;
92 }
93
94 /** ****************************************************************************************
95 * Write the given region of the given AString to the destination buffer.
96 *
97 * @param buffer The string to write a portion of.
98 * @param start The start of the portion in \p{buffer} to write out.
99 * @param length The length of the portion in \p{buffer} to write out.
100 * @return The number of characters written, -1 on error.
101 ******************************************************************************************/
102 virtual integer logSubstring( const String& buffer,
103 integer start, integer length ) override
104 {
105 MemoryLog._<false>( buffer, start, length );
107 ? buffer.Substring<false>( start, length ).WStringLength()
108 : length;
109 }
110
111 /** ****************************************************************************************
112 * Empty implementation, not needed for this class
113 ******************************************************************************************/
114 virtual void notifyMultiLineOp( lang::Phase ) override {}
115
116}; // class MemoryLogger
117
118}} // namespace alib[::lox::loggers]
119
120/// Type alias in namespace \b alib.
122
123} // namespace [alib]
124
125#endif // HPP_ALOX_MEMORY_LOGGER
PlainTextLogger(const NString &name, const NString &typeName, bool pUsesStdStreams)
virtual void notifyMultiLineOp(lang::Phase) override
virtual bool notifyLogOp(lang::Phase phase) override
MemoryLogger(const NString &name=nullptr, bool pruneESCSequences=true, bool useWStringLengthForTabAdjustments=true)
virtual integer logSubstring(const String &buffer, integer start, integer length) override
TAString & _(const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN)
Definition astring.hpp:1056
ALIB_API void SetBuffer(integer newCapacity)
Definition astring.cpp:107
constexpr bool IsNotEmpty() const
Definition string.hpp:420
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
Definition string.hpp:314
@ Begin
The start of a transaction.
Definition alib.cpp:57
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286