ALib C++ Library
by
Library Version:
2402 R1
Documentation generated by
Loading...
Searching...
No Matches
home
dev
A-Worx
ALib
src
alib
alox
loggers
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)
13
#include "
alib/alox/detail/textlogger/plaintextlogger.hpp
"
14
#endif
15
16
namespace
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
**************************************************************************************************/
22
class
MemoryLogger
:
public
alib::lox::detail::textlogger::PlainTextLogger
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
*/
35
AString
MemoryLog
;
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
*/
44
bool
UseWStringLengthForTabAdjustments
=
true
;
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
() )
90
MemoryLog
.
NewLine
();
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 );
106
return
UseWStringLengthForTabAdjustments
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.
121
using
MemoryLogger
=
lox::loggers::MemoryLogger
;
122
123
}
// namespace [alib]
124
125
#endif
// HPP_ALOX_MEMORY_LOGGER
alib::lox::detail::textlogger::PlainTextLogger
Definition
plaintextlogger.hpp:28
alib::lox::detail::textlogger::PlainTextLogger::PlainTextLogger
PlainTextLogger(const NString &name, const NString &typeName, bool pUsesStdStreams)
Definition
plaintextlogger.hpp:54
alib::lox::detail::textlogger::PlainTextLogger::PruneESCSequences
bool PruneESCSequences
Definition
plaintextlogger.hpp:41
alib::lox::loggers::MemoryLogger
Definition
memorylogger.hpp:23
alib::lox::loggers::MemoryLogger::notifyMultiLineOp
virtual void notifyMultiLineOp(lang::Phase) override
Definition
memorylogger.hpp:114
alib::lox::loggers::MemoryLogger::notifyLogOp
virtual bool notifyLogOp(lang::Phase phase) override
Definition
memorylogger.hpp:86
alib::lox::loggers::MemoryLogger::UseWStringLengthForTabAdjustments
bool UseWStringLengthForTabAdjustments
Definition
memorylogger.hpp:44
alib::lox::loggers::MemoryLogger::~MemoryLogger
virtual ~MemoryLogger() override
Definition
memorylogger.hpp:74
alib::lox::loggers::MemoryLogger::MemoryLogger
MemoryLogger(const NString &name=nullptr, bool pruneESCSequences=true, bool useWStringLengthForTabAdjustments=true)
Definition
memorylogger.hpp:60
alib::lox::loggers::MemoryLogger::MemoryLog
AString MemoryLog
Definition
memorylogger.hpp:35
alib::lox::loggers::MemoryLogger::logSubstring
virtual integer logSubstring(const String &buffer, integer start, integer length) override
Definition
memorylogger.hpp:102
alib::strings::TAString< character >
alib::strings::TAString::NewLine
TAString & NewLine()
Definition
astring.hpp:1066
alib::strings::TAString::_
TAString & _(const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN)
Definition
astring.hpp:1056
alib::strings::TAString::SetBuffer
ALIB_API void SetBuffer(integer newCapacity)
Definition
astring.cpp:107
alib::strings::TString< nchar >
alib::strings::TString::IsNotEmpty
constexpr bool IsNotEmpty() const
Definition
string.hpp:420
alib::strings::TString::Substring
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
Definition
string.hpp:314
alib::lang::Phase
Phase
Definition
commonenumdefs.hpp:139
alib::lang::Phase::Begin
@ Begin
The start of a transaction.
alib
Definition
alib.cpp:57
alib::integer
lang::integer integer
Type alias in namespace alib.
Definition
integers.hpp:286
plaintextlogger.hpp