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