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.
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< ThreadLock > | acquirers =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) | |
|
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. |
|
inline |
Creates a ConsoleLogger.
name | (Optional) The name of the Logger, defaults to "COLOR_CONSOLE" |
|
inlineprotectedvirtual |
The implementation of the abstract method of parent class TextLogger. Logs messages to the application console and/or the VStudio output window.
domain | The Log Domain. |
verbosity | The verbosity. This has been checked to be active already on this stage and is provided to be able to be logged out only. |
msg | The log message. |
scope | Information about the scope of the Log Statement.. |
lineNumber | The line number of a multi-line message, starting with 0. For single line messages this is -1. |
Implements TextLogger.
|
inlineprotectedvirtual |
Empty implementation, not needed for this class
phase | Indicates the beginning or end of a multi-line operation. |
Implements TextLogger.
|
protected |
Conversion table from ESC to dark colors
|
protected |
Conversion table from ESC to light colors
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 .