ALib C++ Library
by
Library Version:
2510 R0
Documentation generated by
Loading...
Searching...
No Matches
home
dev
A-Worx
ALib
src
alib
alox
loggers
windowsconsolelogger.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
//==================================================================================================
8
#if defined( _WIN32 ) || DOXYGEN
9
10
ALIB_EXPORT
namespace
alib
{
namespace
lox
{
namespace
loggers
{
11
12
//==================================================================================================
13
/// A logger that logs all messages to the standard output <em>cout</em>.
14
/// The name of the \e Logger defaults to "WINDOWS_CONSOLE".
15
///
16
/// \alox text logger escape sequences (see class \ref alib::lox::ESC "ESC")
17
/// are translated to Windows API calls (<em>SetConsoleTextAttribute</em>) which manipulates
18
/// colors the text output.
19
/// There is not 100% match between windows console capabilities and the definitions in
20
/// \ref alib::lox::ESC "ESC". Especially, ESC style attributes are ignored.
21
///
22
/// Foreground and background colors can be set to be either light/dark or dark/light. This improves
23
/// the readability of log output a lot and even allows reading if foreground and background colors
24
/// are the same (they then still differ). However, the right setting for this is dependent on
25
/// the color scheme of the final output device (window). To manipulate the right setting, see the
26
/// field #CFP and also configuration variable \ref alxcvALOX_CONSOLE_LIGHT_COLORS.
27
///
28
/// In the method #AcknowledgeLox, the default meta info string and color settings are changed
29
/// to fit this logger.
30
///
31
/// \note This class cannot enable the output console (which receives \alox log data) to support
32
/// the windows API call <em>SetConsoleTextAttribute</em>.
33
/// The opposite is right: this class should be used only if the output console supports such
34
/// calls.
35
//==================================================================================================
36
class
WindowsConsoleLogger
:
public
alib::lox::textlogger::TextLogger
37
{
38
// #############################################################################################
39
// Internals
40
// #############################################################################################
41
protected
:
42
/// The attributes that were set on the windows console at the time this object was created.
43
WORD
originalConsoleAttributes
;
44
45
// #############################################################################################
46
// public fields
47
// #############################################################################################
48
public
:
49
50
/// The code page that is used for the console log output. For possible values refer to
51
/// \https{Microsoft documentation,msdn.microsoft.com/EN-US/library/windows/desktop/dd317756%28v=vs.85%29.aspx}
52
///
53
/// This defaults to 65001, which is UTF-8 unicode encoding.
54
///
55
/// This flag can be modified from outside any time. If the value is not equal to 0,
56
/// the code page of the output console is set before each log output.
57
///
58
/// The configuration variable \ref alxcvALOX_CODEPAGE is evaluated within the constructor of
59
/// this class, to allow to modifying the codepage at run-time.
60
UINT
CodePage
=65001;
61
62
/// @see \alib{lox::loggers;AnsiLogger::CFP}.
63
textlogger::ColorfulLoggerParameters
CFP
;
64
65
66
// #############################################################################################
67
// Constructor/destructor
68
// #############################################################################################
69
public
:
70
//==========================================================================================
71
/// Creates a WindowsConsoleLogger.
72
/// @param name (Optional) The name of the \e Logger, defaults to "WINDOWS_CONSOLE".
73
//==========================================================================================
74
ALIB_DLL
75
explicit
WindowsConsoleLogger
(
const
NString
& name=
nullptr
);
76
77
//==========================================================================================
78
/// Destructs a WindowsConsoleLogger
79
//==========================================================================================
80
virtual
~WindowsConsoleLogger
() {}
81
82
83
// #############################################################################################
84
// Abstract method implementations
85
// #############################################################################################
86
protected
:
87
//==========================================================================================
88
/// The implementation of the abstract method of parent class TextLogger.
89
/// Logs messages to the basic output stream 'cout' and sets windows console colors
90
/// by invoking corresponding Windows API methods..
91
///
92
/// @param domain The <em>Log Domain</em>.
93
/// @param verbosity The verbosity. This has been checked to be active already on this
94
/// stage and is provided to be able to be logged out only.
95
/// @param msg The log message.
96
/// @param scope Information about the scope of the <em>Log Statement</em>..
97
/// @param lineNumber The line number of a multi-line message, starting with 0. For
98
/// single line messages this is -1.
99
//==========================================================================================
100
ALIB_DLL
101
virtual
void
logText
(
detail::Domain
& domain,
102
Verbosity
verbosity,
103
AString
& msg,
104
detail::ScopeInfo
& scope,
105
int
lineNumber);
106
107
//==========================================================================================
108
/// Empty implementation, not needed for this class
109
//==========================================================================================
110
ALIB_DLL
111
virtual
void
notifyMultiLineOp
(
lang::Phase
) {}
112
113
//==========================================================================================
114
/// Invokes parent method. Then reads and interprets configuration variable
115
/// \ref alxcvALOX_CONSOLE_LIGHT_COLORS. Finally it is checked if variable
116
/// \ref alxcvALOX_LOGGERNAME_FORMAT has priority of default values, and if yes, such
117
/// values are overwritten to include ANSI color codes. These color codes are retrieved from
118
/// resources named <c>"Var_D21A"</c>.
119
///
120
/// @param lox The \b %Lox to acknowledge insertion or removal
121
/// @param op The operation. Either \b ContainerOp::Insert or \b ContainerOp::Remove.
122
//==========================================================================================
123
ALIB_DLL
124
virtual
void
AcknowledgeLox
( detail::LoxImpl*
lox
,
lang::ContainerOp
op )
override
;
125
126
127
128
};
// class WindowsConsoleLogger
129
130
}}
// namespace alib[::lox::loggers]
131
132
/// Type alias in namespace \b alib.
133
using
WindowsConsoleLogger
=
lox::loggers::WindowsConsoleLogger
;
134
135
}
// namespace [alib]
136
137
#endif
// defined( _WIN32 )
138
139
alib::lox::detail::Domain
Definition
domain.inl:51
alib::lox::detail::ScopeInfo
Definition
scopeinfo.inl:28
alib::lox::loggers::WindowsConsoleLogger
Definition
windowsconsolelogger.inl:37
alib::lox::loggers::WindowsConsoleLogger::~WindowsConsoleLogger
virtual ~WindowsConsoleLogger()
Destructs a WindowsConsoleLogger.
Definition
windowsconsolelogger.inl:80
alib::lox::loggers::WindowsConsoleLogger::CFP
textlogger::ColorfulLoggerParameters CFP
Definition
windowsconsolelogger.inl:63
alib::lox::loggers::WindowsConsoleLogger::WindowsConsoleLogger
ALIB_DLL WindowsConsoleLogger(const NString &name=nullptr)
Definition
windowsconsolelogger.cpp:74
alib::lox::loggers::WindowsConsoleLogger::notifyMultiLineOp
virtual ALIB_DLL void notifyMultiLineOp(lang::Phase)
Empty implementation, not needed for this class.
Definition
windowsconsolelogger.inl:111
alib::lox::loggers::WindowsConsoleLogger::logText
virtual ALIB_DLL void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber)
Definition
windowsconsolelogger.cpp:126
alib::lox::loggers::WindowsConsoleLogger::originalConsoleAttributes
WORD originalConsoleAttributes
The attributes that were set on the windows console at the time this object was created.
Definition
windowsconsolelogger.inl:43
alib::lox::loggers::WindowsConsoleLogger::AcknowledgeLox
virtual ALIB_DLL void AcknowledgeLox(detail::LoxImpl *lox, lang::ContainerOp op) override
Definition
windowsconsolelogger.cpp:88
alib::lox::loggers::WindowsConsoleLogger::CodePage
UINT CodePage
Definition
windowsconsolelogger.inl:60
alib::lox::textlogger::TextLogger
Definition
textlogger.inl:160
ALIB_DLL
#define ALIB_DLL
Definition
alib.inl:496
ALIB_EXPORT
#define ALIB_EXPORT
Definition
alib.inl:488
alib::lang::ContainerOp
ContainerOp
Denotes standard container operations.
Definition
commonenumdefs.inl:65
alib::lang::Phase
Phase
Denotes a phase, e.g.,of a transaction.
Definition
commonenumdefs.inl:127
alib::lox::loggers
Definition
ansilogger.cpp:36
alib::lox
Definition
alox.cpp:62
alib::lox::Verbosity
Verbosity
Definition
alox_init.inl:53
alib
Definition
ALib.Boxing.StdFunctors.H:18
alib::AString
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
Definition
tastring.inl:2162
alib::NString
strings::TString< nchar > NString
Type alias in namespace alib.
Definition
string.inl:2390
alib::WindowsConsoleLogger
lox::loggers::WindowsConsoleLogger WindowsConsoleLogger
Type alias in namespace alib.
Definition
windowsconsolelogger.inl:133
alib::lox::textlogger::ColorfulLoggerParameters
Parameters specific to colorful loggers. As of today, this simply has one attribute.
Definition
variables.inl:344