ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Public Types | Public Fields | Public Methods | Protected Fields | Protected Methods | List of all members
ColorConsoleLogger Class Reference
Inheritance diagram for ColorConsoleLogger:
[legend]
Collaboration diagram for ColorConsoleLogger:
[legend]

Class Description


A logger that logs all messages using the .Net class System.Console. Converts color sequences defined in class ESC that are found within the log messages (and meta info format strings) to a corresponding color setting of class System.Console.

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.

Note
The implementation of class System.Console and its color support is system dependent. E.g. under Mono V. 4.0.2. it was observed that dark and light colors are equal in effect. Therefore, it might be advisable to use a different type of console logger on certain platforms. E.g. under Linux with standard terminal output, class AnsiConsoleLogger might lead to better readable results.

The name of the Logger defaults to "COLORCONSOLE".

Public Types

enum  LightColorUsage { _Undefined, Never, ForegroundLight, ForegroundDark }
 

Public Fields

LightColorUsage UseLightColors
 
- Public Fields inherited from TextLogger
AutoSizes AutoSizes = new AutoSizes()
 
ObjectConverter Converter
 
String FmtMsgSuffix =""
 
String FmtMultiLineMsgHeadline ="ALox: Multi line message follows: "
 Headline for multi line messages (depending on MultiLineMsgMode).
 
String FmtMultiLinePrefix =">> "
 
String FmtMultiLineSuffix =null
 
MetaInfo MetaInfo =new MetaInfo()
 
String MultiLineDelimiter =null
 
String MultiLineDelimiterRepl ="\\r"
 
int MultiLineMsgMode =2
 
- Public Fields inherited from Logger
int CntLogs
 
Ticks TimeOfCreation = new Ticks()
 The creation time of the Logger.
 
Ticks TimeOfLastLog = new Ticks()
 Timestamp of the last log operation.
 
- Public Fields inherited from ThreadLock
int RecursionWarningThreshold =10
 
int waitWarningTimeLimitInMillis =1000
 

Public Methods

 ColorConsoleLogger (String name=null)
 
- Public Methods inherited from TextLogger
override int AddAcquirer (ThreadLock newAcquirer)
 
void ClearReplacements ()
 
override void Log (Domain domain, Verbosity verbosity, List< Object > logables, ScopeInfo scope)
 
override int RemoveAcquirer (ThreadLock acquirer)
 
void ResetAutoSizes ()
 
void SetReplacement (String searched, String replacement)
 
- Public Methods inherited from Logger
String GetName ()
 
String GetTypeName ()
 
override String ToString ()
 
- Public Methods inherited from SmartLock
 SmartLock ()
 
int CntAcquirers ()
 
- Public Methods inherited from ThreadLock
 ThreadLock (LockMode lockMode=LockMode.Recursive, Safeness safeness=Safeness.Safe)
 
virtual void Acquire ([CallerLineNumber] int cln=0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="")
 
int DbgCountAcquirements (Thread thread=null)
 
LockMode GetMode ()
 
Safeness GetSafeness ()
 
virtual void Release ()
 
void SetSafeness (Safeness safeness)
 
override String ToString ()
 
bool WillRelease ()
 

Protected Fields

ConsoleColor[] darkColors
 
ConsoleColor[] lightColors
 
- Protected Fields inherited from TextLogger
AString logBuf =new AString( 256 )
 
AString msgBuf =new AString( 128 )
 
List< String > replacements =new List<String>()
 
int stdStreamLockRegistrationCounter =0
 
bool usesStdStreams
 
- Protected Fields inherited from Logger
String Name
 
String TypeName
 
- Protected Fields inherited from SmartLock
List< ThreadLockacquirers =new List<ThreadLock>()
 
- Protected Fields inherited from ThreadLock
int cntAcquirements
 
LockMode lockMode
 
Object mutex
 
Thread owner
 
Ticks waitTime =new Ticks()
 

Protected Methods

override void logText (Domain domain, Verbosity verbosity, AString msg, ScopeInfo scope, int lineNumber)
 
override void notifyMultiLineOp (Phase phase)
 
- Protected Methods inherited from TextLogger
 TextLogger (String name, String typeName, bool usesStdStreams)
 
- Protected Methods inherited from Logger
 Logger (String name, String typeName)
 

Member Enumeration Documentation

◆ LightColorUsage

enum LightColorUsage
strong

Denotes states of field UseLightColors.

Enumerator
_Undefined 

Internal, temporary state.

Never 

Never use light colors.

ForegroundLight 

Use light colors for foreground.

ForegroundDark 

Use light colors for background.

Constructor & Destructor Documentation

◆ ColorConsoleLogger()

ColorConsoleLogger ( String  name = null)
inline

Creates a ConsoleLogger.

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

Member Function Documentation

◆ logText()

override void logText ( Domain  domain,
Verbosity  verbosity,
AString  msg,
ScopeInfo  scope,
int  lineNumber 
)
inlineprotectedvirtual

The implementation of the abstract method of parent class TextLogger. Logs messages to the application console and/or the VStudio output window.

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.

◆ notifyMultiLineOp()

override void notifyMultiLineOp ( Phase  phase)
inlineprotectedvirtual

Empty implementation, not needed for this class

Parameters
phaseIndicates the beginning or end of a multi-line operation.

Implements TextLogger.

Member Data Documentation

◆ darkColors

ConsoleColor [] darkColors
protected
Initial value:
= {
ConsoleColor.DarkRed ,
ConsoleColor.DarkGreen ,
ConsoleColor.DarkYellow ,
ConsoleColor.DarkBlue ,
ConsoleColor.DarkMagenta,
ConsoleColor.DarkCyan ,
ConsoleColor.Black ,
ConsoleColor.White ,
ConsoleColor.DarkGray ,
}

Conversion table from ESC to dark colors

◆ lightColors

ConsoleColor [] lightColors
protected
Initial value:
= {
ConsoleColor.Red ,
ConsoleColor.Green ,
ConsoleColor.Yellow ,
ConsoleColor.Blue ,
ConsoleColor.Magenta,
ConsoleColor.Cyan ,
ConsoleColor.Black ,
ConsoleColor.White ,
ConsoleColor.Gray ,
}

Conversion table from ESC to light colors

◆ 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 .


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