ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
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_ALOX_WINDOWS_CONSOLE_LOGGER
9#define HPP_ALOX_WINDOWS_CONSOLE_LOGGER 1
10
11#if !defined (HPP_ALOX_DETAIL_TEXTLOGGER_TEXTLOGGER)
13#endif
14
15#if defined( _WIN32 ) || defined(ALIB_DOX)
16
17namespace alib { namespace lox { namespace loggers {
18
19/** ************************************************************************************************
20 * A logger that logs all messages to the standard output <em>cout</em>.
21 * The name of the \e Logger defaults to "WINDOWS_CONSOLE".
22 *
23 * \alox text logger escape sequences (see class \ref alib::lox::ESC "ESC")
24 * are translated to Windows API calls (<em>SetConsoleTextAttribute</em>) which manipulates
25 * colors the text output.
26 * There is not 100% match between windows console capabilities and the definitions in
27 * \ref alib::lox::ESC "ESC". Especially, ESC style attributes are ignored.
28 *
29 * Foreground and background colors can be set to be either light/dark or dark/light. This improves
30 * the readability of log output a lot and even allows to read if foreground and background colors
31 * are the same (they then still differ). However, the right setting for this is dependent on
32 * the color scheme of the final output device (window). To manipulate the right setting, see field
33 * #UseLightColors and also configuration variable \ref alxcvALOX_CONSOLE_LIGHT_COLORS.
34 *
35 * In the constructor, a default format string and some other definitions in member
36 * \ref MetaInfo get set to include ESC sequences. Of-course, these publicly accessible
37 * format attributes can be customized after creation.
38 *
39 * \note This class can not enable the output console (which receives \alox
40 * log data) to support the windows API call <em>SetConsoleTextAttribute</em>.
41 * The opposite is right: this class should be used only if the output console supports such calls.
42 **************************************************************************************************/
44{
45 // #############################################################################################
46 // Internals
47 // #############################################################################################
48 protected:
49 /** The attributes that were set on the windows console at the time this object was created. */
51
52 // #############################################################################################
53 // public fields
54 // #############################################################################################
55 public:
56
57 /**
58 * Foreground and background colors chosen by this class might differ in their intensity.
59 * This increases the overall readability by increasing the contrast.
60 * If the background color of a console window is dark, then the background colors of
61 * colored log output should be darker colors than the foreground colors - and vice versa.
62 *
63 * Depending on the setting of this field, \alox
64 * \ref alib::lox::ESC "escape codes" for colors are translated to normal ANSI colors or
65 * lighter ones:
66 * - If this field is \ref LightColorUsage "LightColorUsage::Never", light colors are
67 * never used.
68 * - If this field is \ref LightColorUsage "LightColorUsage::ForegroundLight", foreground
69 * colors will be light colors and background colors dark ones. This is the default.
70 * - If \ref LightColorUsage "LightColorUsage::ForegroundDark", background colors will be
71 * light colors and foreground colors dark ones.
72 *
73 * The configuration variable \ref alxcvALOX_CONSOLE_LIGHT_COLORS allows to externally modify
74 * this flag. It is read once within the constructor.
75 */
77
78 /**
79 * The code page that is used for the console log output. For possible values refer to
80 * \https{Microsoft documentation,msdn.microsoft.com/EN-US/library/windows/desktop/dd317756%28v=vs.85%29.aspx}
81 *
82 * This defaults to 65001, which is UTF-8 unicode encoding.
83 *
84 * This flag can be modified from outside any time. If the value is not equal to 0,
85 * the code page of the output console is set prior to each log output.
86 *
87 * The configuration variable \ref alxcvALOX_CODE_PAGE is evaluated within the constructor of
88 * this class, to allow to modifying the codepage at run-time.
89 */
90
91 UINT CodePage =65001;
92
93 // #############################################################################################
94 // Constructor/destructor
95 // #############################################################################################
96 public:
97 /** ****************************************************************************************
98 * Creates a WindowsConsoleLogger.
99 * @param name (Optional) The name of the \e Logger, defaults to "WINDOWS_CONSOLE".
100 ******************************************************************************************/
102 explicit WindowsConsoleLogger( const NString& name= nullptr );
103
104 /** ****************************************************************************************
105 * Destructs a WindowsConsoleLogger
106 ******************************************************************************************/
108 virtual ~WindowsConsoleLogger();
109
110
111 // #############################################################################################
112 // Abstract method implementations
113 // #############################################################################################
114 protected:
115 /** ****************************************************************************************
116 * The implementation of the abstract method of parent class TextLogger.
117 * Logs messages to the basic output stream 'cout' and sets windows console colors
118 * by invoking corresponding Windows API methods..
119 *
120 * @param domain The <em>Log Domain</em>.
121 * @param verbosity The verbosity. This has been checked to be active already on this
122 * stage and is provided to be able to be logged out only.
123 * @param msg The log message.
124 * @param scope Information about the scope of the <em>Log Statement</em>..
125 * @param lineNumber The line number of a multi-line message, starting with 0. For
126 * single line messages this is -1.
127 ******************************************************************************************/
129 virtual void logText( detail::Domain& domain,
130 Verbosity verbosity,
131 AString& msg,
132 detail::ScopeInfo& scope,
133 int lineNumber);
134
135 /** ****************************************************************************************
136 * Empty implementation, not needed for this class
137 ******************************************************************************************/
139 virtual void notifyMultiLineOp (lang::Phase ) { }
140
141}; // class WindowsConsoleLogger
142
143}} // namespace alib[::lox::loggers]
144
145/// Type alias in namespace \b alib.
147
148} // namespace [alib]
149
150#endif // defined( _WIN32 )
151
152#endif // HPP_ALOX_WINDOWS_CONSOLE_LOGGER
virtual ALIB_API void logText(detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber)
virtual ALIB_API void notifyMultiLineOp(lang::Phase)
#define ALIB_API
Definition alib.hpp:538
Definition alib.cpp:57
lox::loggers::WindowsConsoleLogger WindowsConsoleLogger
Type alias in namespace alib.