ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
WindowsConsoleLogger Class Reference

Description:


A logger that logs all messages to the standard output cout. The name of the Logger defaults to "WINDOWS_CONSOLE".

ALox text logger escape sequences (see class ESC) are translated to Windows API calls (SetConsoleTextAttribute) which manipulates colors the text output. There is not 100% match between windows console capabilities and the definitions in ESC. Especially, ESC style attributes are ignored.

Foreground and background colors can be set to be either light/dark or dark/light. This improves the readability of log output a lot and even allows to read if foreground and background colors are the same (they then still differ). However, the right setting for this is dependent on the color scheme of the final output device (window). To manipulate the right setting, see field UseLightColors and also configuration variable ALOX_CONSOLE_LIGHT_COLORS.

In the constructor, a default format string and some other definitions in member MetaInfo get set to include ESC sequences. Of-course, these publicly accessible format attributes can be customized after creation.

Note
This class can not enable the output console (which receives ALox log data) to support the windows API call SetConsoleTextAttribute. The opposite is right: this class should be used only if the output console supports such calls.

Definition at line 43 of file windowsconsolelogger.hpp.

#include <windowsconsolelogger.hpp>

Inheritance diagram for WindowsConsoleLogger:
[legend]
Collaboration diagram for WindowsConsoleLogger:
[legend]

Public Field Index:

UINT CodePage =65001
 
LightColorUsage UseLightColors
 
- Public Field Index: inherited from TextLogger
strings::util::AutoSizes AutoSizes
 
ObjectConverterConverter = nullptr
 
String16 FmtMsgSuffix
 
String64 FmtMultiLineMsgHeadline = A_CHAR("ALox: Multi line message follows: ")
 
String16 FmtMultiLinePrefix = A_CHAR(">> ")
 
String16 FmtMultiLineSuffix = A_CHAR("")
 
textlogger::MetaInfoMetaInfo
 
AString MultiLineDelimiter
 
String16 MultiLineDelimiterRepl = A_CHAR("\\r")
 
int MultiLineMsgMode =2
 
- Public Field Index: inherited from Logger
integer CntLogs =0
 
time::Ticks TimeOfCreation
 
time::Ticks TimeOfLastLog
 
- Public Field Index: inherited from ThreadLock
NCString DbgOwnerFile =nullptr
 
NCString DbgOwnerFunc =nullptr
 
int DbgOwnerLine
 
uint16_t DbgRecursionWarningThreshold =10
 
integer DbgWarningAfterWaitTimeInMillis =2000L
 

Public Method Index:

ALIB_API WindowsConsoleLogger (const NString &name=nullptr)
 
virtual ALIB_API ~WindowsConsoleLogger ()
 
- Public Method Index: inherited from TextLogger
virtual ALIB_API ~TextLogger () override
 
virtual ALIB_API void AcknowledgeLox (LoxImpl *lox, lang::ContainerOp op) override
 
virtual ALIB_API void ClearReplacements ()
 
virtual ALIB_API void Log (Domain &domain, Verbosity verbosity, Boxes &logables, ScopeInfo &scope) override
 
virtual ALIB_API void ResetAutoSizes ()
 
virtual ALIB_API void SetReplacement (const String &searched, const String &replacement)
 
- Public Method Index: inherited from Logger
virtual ~Logger ()
 
const NStringGetName () const
 
const NStringGetTypeName () const
 
- Public Method Index: inherited from SmartLock
 SmartLock ()
 
void Acquire (const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
 
ALIB_API int AddAcquirer (ThreadLock *newAcquirer)
 
ALIB_API int CntAcquirers ()
 
ALIB_API void Release ()
 defined(ALIB_DOX)
 
ALIB_API int RemoveAcquirer (ThreadLock *acquirer)
 
- Public Method Index: inherited from ThreadLock
ALIB_API ThreadLock (lang::Safeness safeness=lang::Safeness::Safe)
 
ALIB_API ~ThreadLock ()
 
ALIB_API void Acquire (const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
 
int CountAcquirements () const
 
ThreadGetOwner () const
 
lang::Safeness GetSafeness () const
 
bool IsOwnedByCurrentThread () const
 
ALIB_API void Release ()
 defined(ALIB_DOX)
 
ALIB_API void SetSafeness (lang::Safeness safeness)
 
bool WillRelease () const
 

Additional Inherited Members

- Public Type Index: inherited from TextLogger
enum class  LightColorUsage { Auto , Never , Foreground , Background }
 
- Public Static Field Index: inherited from SmartLock
static ALIB_API SmartLock StdOutputStreams
 

Field Details:

◆ CodePage

UINT CodePage =65001

The code page that is used for the console log output. For possible values refer to Microsoft documentation

This defaults to 65001, which is UTF-8 unicode encoding.

This flag can be modified from outside any time. If the value is not equal to 0, the code page of the output console is set prior to each log output.

The configuration variable ALOX_CODE_PAGE is evaluated within the constructor of this class, to allow to modifying the codepage at run-time.

Definition at line 91 of file windowsconsolelogger.hpp.

◆ originalConsoleAttributes

WORD originalConsoleAttributes
protected

The attributes that were set on the windows console at the time this object was created.

Definition at line 50 of file windowsconsolelogger.hpp.

◆ UseLightColors

LightColorUsage UseLightColors

Foreground and background colors chosen by this class might differ in their intensity. This increases the overall readability by increasing the contrast. If the background color of a console window is dark, then the background colors of colored log output should be darker colors than the foreground colors - and vice versa.

Depending on the setting of this field, ALox escape codes for colors are translated to normal ANSI colors or lighter ones:

The configuration variable ALOX_CONSOLE_LIGHT_COLORS allows to externally modify this flag. It is read once within the constructor.

Definition at line 76 of file windowsconsolelogger.hpp.

Constructor(s) / Destructor Details::

◆ WindowsConsoleLogger()

WindowsConsoleLogger ( const NString & name = nullptr)
explicit

Creates a WindowsConsoleLogger.

Parameters
name(Optional) The name of the Logger, defaults to "WINDOWS_CONSOLE".

Definition at line 80 of file windowsconsolelogger.cpp.

Here is the call graph for this function:

◆ ~WindowsConsoleLogger()

~WindowsConsoleLogger ( )
virtual

Destructs a WindowsConsoleLogger

Definition at line 128 of file windowsconsolelogger.cpp.

Method Details:

◆ logText()

void logText ( detail::Domain & domain,
Verbosity verbosity,
AString & msg,
detail::ScopeInfo & scope,
int lineNumber )
protectedvirtual

The implementation of the abstract method of parent class TextLogger. Logs messages to the basic output stream 'cout' and sets windows console colors by invoking corresponding Windows API methods..

Parameters
domainThe Log Domain.
verbosityThe verbosity. This has been checked to be active already on this stage and is provided to be able to be logged out only.
msgThe log message.
scopeInformation about the scope of the Log Statement..
lineNumberThe line number of a multi-line message, starting with 0. For single line messages this is -1.

Implements TextLogger.

Definition at line 135 of file windowsconsolelogger.cpp.

Here is the call graph for this function:

◆ notifyMultiLineOp()

virtual ALIB_API void notifyMultiLineOp ( lang::Phase )
inlineprotectedvirtual

Empty implementation, not needed for this class

Implements TextLogger.

Definition at line 139 of file windowsconsolelogger.hpp.


The documentation for this class was generated from the following files: