ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
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
10ALIB_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//==================================================================================================
37{
38 // #############################################################################################
39 // Internals
40 // #############################################################################################
41 protected:
42 /// The attributes that were set on the windows console at the time this object was created.
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}.
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 //==========================================================================================
75 explicit WindowsConsoleLogger( const NString& name= nullptr );
76
77 //==========================================================================================
78 /// Destructs a WindowsConsoleLogger
79 //==========================================================================================
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 //==========================================================================================
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 //==========================================================================================
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 //==========================================================================================
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.
134
135} // namespace [alib]
136
137#endif // defined( _WIN32 )
138
139
virtual ~WindowsConsoleLogger()
Destructs a WindowsConsoleLogger.
textlogger::ColorfulLoggerParameters CFP
ALIB_DLL WindowsConsoleLogger(const NString &name=nullptr)
virtual ALIB_DLL void notifyMultiLineOp(lang::Phase)
Empty implementation, not needed for this class.
virtual ALIB_DLL void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber)
WORD originalConsoleAttributes
The attributes that were set on the windows console at the time this object was created.
virtual ALIB_DLL void AcknowledgeLox(detail::LoxImpl *lox, lang::ContainerOp op) override
#define ALIB_DLL
Definition alib.inl:496
#define ALIB_EXPORT
Definition alib.inl:488
ContainerOp
Denotes standard container operations.
Phase
Denotes a phase, e.g.,of a transaction.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2390
lox::loggers::WindowsConsoleLogger WindowsConsoleLogger
Type alias in namespace alib.
Parameters specific to colorful loggers. As of today, this simply has one attribute.