ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Public Fields | Public Methods | Protected Fields | Protected Methods | List of all members
WindowsConsoleLogger Class Reference

#include <windowsconsolelogger.hpp>

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

Class 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 46 of file windowsconsolelogger.hpp.

Public Fields

UINT CodePage =65001
 
LightColorUsage UseLightColors
 
- Public Fields inherited from TextLogger
lib::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 Fields inherited from Logger
integer CntLogs =0
 
lib::time::Ticks TimeOfCreation
 
lib::time::Ticks TimeOfLastLog
 
- Public Fields inherited from ThreadLock
NCString DbgOwnerFile =nullptr
 
NCString DbgOwnerFunc =nullptr
 
int DbgOwnerLine
 
uint16_t DbgRecursionWarningThreshold =10
 
integer DbgWarningAfterWaitTimeInMillis =2000L
 

Public Methods

ALIB_API WindowsConsoleLogger (const NString &name=nullptr)
 
virtual ALIB_API ~WindowsConsoleLogger ()
 
- Public Methods inherited from TextLogger
virtual ALIB_API ~TextLogger () override
 
virtual ALIB_API void AcknowledgeLox (LoxImpl *lox, 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 Methods inherited from Logger
virtual ~Logger ()
 
const NStringGetName () const
 
const NStringGetTypeName () const
 
- Public Methods 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) More...
 
ALIB_API int RemoveAcquirer (ThreadLock *acquirer)
 
- Public Methods inherited from ThreadLock
ALIB_API ThreadLock (Safeness safeness=Safeness::Safe)
 
ALIB_API ~ThreadLock ()
 
ALIB_API void Acquire (const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
 
int CountAcquirements () const
 
ThreadGetOwner () const
 
Safeness GetSafeness () const
 
bool IsOwnedByCurrentThread () const
 
ALIB_API void Release ()
 defined(ALIB_DOX) More...
 
ALIB_API void SetSafeness (Safeness safeness)
 
bool WillRelease () const
 

Protected Fields

WORD originalConsoleAttributes
 
- Protected Fields inherited from TextLogger
AString logBuf
 
AString msgBuf
 
std::vector< AStringreplacements
 
int stdStreamLockRegistrationCounter =0
 
bool usesStdStreams
 
- Protected Fields inherited from Logger
NString32 Name
 
NString32 TypeName
 
- Protected Fields inherited from SmartLock
std::vector< ThreadLock * > acquirers
 
ThreadLockNR lock
 
- Protected Fields inherited from ThreadLock
uint16_t cntAcquirements =0
 
std::mutex mutex
 
std::condition_variable mutexNotifier
 
std::thread::id owner
 
Safeness safeness
 

Protected Methods

virtual ALIB_API void logText (detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber)
 
virtual ALIB_API void notifyMultiLineOp (lib::Phase)
 
- Protected Methods inherited from TextLogger
ALIB_API TextLogger (const NString &pName, const NString &typeName, bool pUsesStdStreams)
 
- Protected Methods inherited from Logger
 Logger (const NString &name, const NString &typeName)
 

Additional Inherited Members

- Public Types inherited from TextLogger
enum  LightColorUsage { Auto, Never, Foreground, Background }
 
- Public Static Fields inherited from SmartLock
static ALIB_API SmartLock StdOutputStreams
 

Constructor & Destructor Documentation

◆ 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 81 of file windowsconsolelogger.cpp.

Here is the call graph for this function:

◆ ~WindowsConsoleLogger()

~WindowsConsoleLogger ( )
virtual

Destructs a WindowsConsoleLogger

Definition at line 130 of file windowsconsolelogger.cpp.

Member Function Documentation

◆ 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 137 of file windowsconsolelogger.cpp.

Here is the call graph for this function:

◆ notifyMultiLineOp()

virtual ALIB_API void notifyMultiLineOp ( lib::Phase  )
inlineprotectedvirtual

Empty implementation, not needed for this class

Implements TextLogger.

Definition at line 145 of file windowsconsolelogger.hpp.

Member Data Documentation

◆ 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 97 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 53 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 80 of file windowsconsolelogger.hpp.


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