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