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

Class Description


A logger that logs all messages to the System.IO.TextWriter instance provided in the constructor. The name of the Logger defaults to "ANSI_LOGGER".

ALox text logger escape sequences (see class ESC) are translated to ANSI escape sequences. Support for ANSI escape sequences (also referred to as VT100 terminal emulation) is available on most unix terminal windows. Besides text colors, bold and italics font style can be set. ANSI escape sequences are also available in various IDE output windows.

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 color settings. Of-course, these publicly accessible format attributes can be customized after creation.

There is not 100% match between the ANSI sequences and the definitions in ESC. For example ESC does not provide all ANSI colors and no blinking. On the other hand, ANSI does not allow to reset the style without resetting the colors. Of-course, it is no problem to log other ANSI codes directly into an AnsiLogger. In this case, other Loggers that might be attached to the same Lox and that do not support ANSI must be equipped with corresponding replacement information. In other words: To support the same log output into different loggers, it is recommended to use ESC sequences instead of directly using ANSI codes.

The ANSI codes used by this class are exposed through a list of fields. They might be useful for manipulating the attributes of the MetaInfo member, which of-course might contain native ANSI sequences. (In contrast to the log messages themselves, this meta information is specific to a logger instance and this way it does not need to be replaced in other loggers).

Public Types

enum  LightColorUsage { _Undefined, Never, ForegroundLight, ForegroundDark }
 

Public Static Fields

static readonly String ANSI_BG_BLACK ="\x001B[40m"
 Select black as background color.
 
static readonly String ANSI_BG_BLUE ="\x001B[44m"
 Select blue as background color.
 
static readonly String ANSI_BG_CYAN ="\x001B[46m"
 Select cyan as background color.
 
static readonly String ANSI_BG_GRAY ="\x001B[48;5;240m"
 Select gray as background color.
 
static readonly String ANSI_BG_GREEN ="\x001B[42m"
 Select green as background color.
 
static readonly String ANSI_BG_LIGHT_BLUE ="\x001B[48;5;12m"
 Select light blue as background color.
 
static readonly String ANSI_BG_LIGHT_CYAN ="\x001B[48;5;14m"
 Select light cyan as background color.
 
static readonly String ANSI_BG_LIGHT_GRAY ="\x001B[48;5;250m"
 Select light gray as background color.
 
static readonly String ANSI_BG_LIGHT_GREEN ="\x001B[48;5;10m"
 Select light green as background color.
 
static readonly String ANSI_BG_LIGHT_MAGENTA ="\x001B[48;5;13m"
 Select light magenta as background color.
 
static readonly String ANSI_BG_LIGHT_RED ="\x001B[48;5;09m"
 Select light red as background color.
 
static readonly String ANSI_BG_LIGHT_YELLOW ="\x001B[48;5;11m"
 Select light yellow as background color.
 
static readonly String ANSI_BG_MAGENTA ="\x001B[45m"
 Select magenta as background color.
 
static readonly String ANSI_BG_RED ="\x001B[41m"
 Select red as background color.
 
static readonly String ANSI_BG_STD_COL ="\x001B[49m"
 Select standard background color.
 
static readonly String ANSI_BG_WHITE ="\x001B[48;5;15m"
 Select white as background color.
 
static readonly String ANSI_BG_YELLOW ="\x001B[43m"
 Select yellow as background color.
 
static readonly String ANSI_BLACK ="\x001B[30m"
 Select black as foreground color.
 
static readonly String ANSI_BLUE ="\x001B[34m"
 Select blue as foreground color.
 
static readonly String ANSI_BOLD ="\x001B[1m"
 Select bold font style.
 
static readonly String ANSI_CYAN ="\x001B[36m"
 Select cyan as foreground color.
 
static readonly String ANSI_GRAY ="\x001B[38;5;240m"
 Select gray as foreground color.
 
static readonly String ANSI_GREEN ="\x001B[32m"
 Select green as foreground color.
 
static readonly String ANSI_ITALICS ="\x001B[3m"
 Select italics font style.
 
static readonly String ANSI_LIGHT_BLUE ="\x001B[38;5;12m"
 Select light blue as foreground color.
 
static readonly String ANSI_LIGHT_CYAN ="\x001B[38;5;14m"
 Select light cyan as foreground color.
 
static readonly String ANSI_LIGHT_GRAY ="\x001B[38;5;250m"
 Select light gray as foreground color.
 
static readonly String ANSI_LIGHT_GREEN ="\x001B[38;5;10m"
 Select light green as foreground color.
 
static readonly String ANSI_LIGHT_MAGENTA ="\x001B[38;5;13m"
 Select light magenta as foreground color.
 
static readonly String ANSI_LIGHT_RED ="\x001B[38;5;09m"
 Select light red as foreground color.
 
static readonly String ANSI_LIGHT_YELLOW ="\x001B[38;5;11m"
 Select light yellow as foreground color.
 
static readonly String ANSI_MAGENTA ="\x001B[35m"
 Select magenta as foreground color.
 
static readonly String ANSI_RED ="\x001B[31m"
 Select red as foreground color.
 
static readonly String ANSI_RESET ="\x001B[0m"
 Reset colors and font style.
 
static readonly String ANSI_STD_COL ="\x001B[39m"
 Select standard foreground color.
 
static readonly String ANSI_STD_STYLE ="\x001B[0m"
 Select standard font style.
 
static readonly String ANSI_WHITE ="\x001B[38;5;15m"
 Select white as foreground color.
 
static readonly String ANSI_YELLOW ="\x001B[33m"
 Select yellow as foreground color.
 

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

 AnsiLogger (System.IO.TextWriter textWriter, bool usesStdStreams, String name=null, String typeName="ANSI")
 
- 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

String[] ansiCols
 
System.IO.TextWriter textWriter
 
- 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

◆ AnsiLogger()

AnsiLogger ( System.IO.TextWriter  textWriter,
bool  usesStdStreams,
String  name = null,
String  typeName = "ANSI" 
)
inline

Creates an AnsiLogger.

Parameters
textWriterThe TextWriter object to write into.
usesStdStreamsDenotes whether this logger writes to the standard output streams.
nameThe name of the Logger, defaults to what is provided with parameter typeName.
typeNameThe type of the Logger, defaults to "ANSI".

Member Function Documentation

◆ logText()

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

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.

Parameters
phaseThe phase of the multi-line operation (ignored).

Implements TextLogger.

Member Data Documentation

◆ ansiCols

String [] ansiCols
protected

◆ textWriter

System.IO.TextWriter textWriter
protected

The TextWriter provided in the constructor.

◆ 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:
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_LIGHT_CYAN
static readonly String ANSI_BG_LIGHT_CYAN
Select light cyan as background color.
Definition: AnsiLogger.cs:108
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_RED
static readonly String ANSI_BG_RED
Select red as background color.
Definition: AnsiLogger.cs:84
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_LIGHT_YELLOW
static readonly String ANSI_BG_LIGHT_YELLOW
Select light yellow as background color.
Definition: AnsiLogger.cs:105
cs.aworx.lox.loggers.AnsiLogger.ANSI_GREEN
static readonly String ANSI_GREEN
Select green as foreground color.
Definition: AnsiLogger.cs:74
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_WHITE
static readonly String ANSI_BG_WHITE
Select white as background color.
Definition: AnsiLogger.cs:91
cs.aworx.lox.loggers.AnsiLogger.ANSI_LIGHT_GRAY
static readonly String ANSI_LIGHT_GRAY
Select light gray as foreground color.
Definition: AnsiLogger.cs:101
cs.aworx.lox.loggers.AnsiLogger.ANSI_CYAN
static readonly String ANSI_CYAN
Select cyan as foreground color.
Definition: AnsiLogger.cs:78
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_STD_COL
static readonly String ANSI_BG_STD_COL
Select standard background color.
Definition: AnsiLogger.cs:93
cs.aworx.lox.loggers.AnsiLogger.ANSI_LIGHT_GREEN
static readonly String ANSI_LIGHT_GREEN
Select light green as foreground color.
Definition: AnsiLogger.cs:96
cs.aworx.lox.loggers.AnsiLogger.ANSI_YELLOW
static readonly String ANSI_YELLOW
Select yellow as foreground color.
Definition: AnsiLogger.cs:75
cs.aworx.lox.loggers.AnsiLogger.ANSI_WHITE
static readonly String ANSI_WHITE
Select white as foreground color.
Definition: AnsiLogger.cs:80
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_LIGHT_BLUE
static readonly String ANSI_BG_LIGHT_BLUE
Select light blue as background color.
Definition: AnsiLogger.cs:106
cs.aworx.lox.loggers.AnsiLogger.ANSI_BLACK
static readonly String ANSI_BLACK
Select black as foreground color.
Definition: AnsiLogger.cs:79
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_BLACK
static readonly String ANSI_BG_BLACK
Select black as background color.
Definition: AnsiLogger.cs:90
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_BLUE
static readonly String ANSI_BG_BLUE
Select blue as background color.
Definition: AnsiLogger.cs:87
cs.aworx.lox.loggers.AnsiLogger.ANSI_RED
static readonly String ANSI_RED
Select red as foreground color.
Definition: AnsiLogger.cs:73
cs.aworx.lox.loggers.AnsiLogger.ANSI_LIGHT_YELLOW
static readonly String ANSI_LIGHT_YELLOW
Select light yellow as foreground color.
Definition: AnsiLogger.cs:97
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_GRAY
static readonly String ANSI_BG_GRAY
Select gray as background color.
Definition: AnsiLogger.cs:92
cs.aworx.lox.loggers.AnsiLogger.ANSI_STD_COL
static readonly String ANSI_STD_COL
Select standard foreground color.
Definition: AnsiLogger.cs:82
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_YELLOW
static readonly String ANSI_BG_YELLOW
Select yellow as background color.
Definition: AnsiLogger.cs:86
cs.aworx.lox.loggers.AnsiLogger.ANSI_MAGENTA
static readonly String ANSI_MAGENTA
Select magenta as foreground color.
Definition: AnsiLogger.cs:77
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_LIGHT_RED
static readonly String ANSI_BG_LIGHT_RED
Select light red as background color.
Definition: AnsiLogger.cs:103
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_GREEN
static readonly String ANSI_BG_GREEN
Select green as background color.
Definition: AnsiLogger.cs:85
cs.aworx.lox.loggers.AnsiLogger.ANSI_LIGHT_MAGENTA
static readonly String ANSI_LIGHT_MAGENTA
Select light magenta as foreground color.
Definition: AnsiLogger.cs:99
cs.aworx.lox.loggers.AnsiLogger.ANSI_BLUE
static readonly String ANSI_BLUE
Select blue as foreground color.
Definition: AnsiLogger.cs:76
cs.aworx.lox.loggers.AnsiLogger.ANSI_LIGHT_BLUE
static readonly String ANSI_LIGHT_BLUE
Select light blue as foreground color.
Definition: AnsiLogger.cs:98
cs.aworx.lox.loggers.AnsiLogger.ANSI_GRAY
static readonly String ANSI_GRAY
Select gray as foreground color.
Definition: AnsiLogger.cs:81
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_MAGENTA
static readonly String ANSI_BG_MAGENTA
Select magenta as background color.
Definition: AnsiLogger.cs:88
cs.aworx.lox.loggers.AnsiLogger.ANSI_LIGHT_CYAN
static readonly String ANSI_LIGHT_CYAN
Select light cyan as foreground color.
Definition: AnsiLogger.cs:100
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_LIGHT_GREEN
static readonly String ANSI_BG_LIGHT_GREEN
Select light green as background color.
Definition: AnsiLogger.cs:104
cs.aworx.lox.loggers.AnsiLogger.ANSI_LIGHT_RED
static readonly String ANSI_LIGHT_RED
Select light red as foreground color.
Definition: AnsiLogger.cs:95
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_LIGHT_MAGENTA
static readonly String ANSI_BG_LIGHT_MAGENTA
Select light magenta as background color.
Definition: AnsiLogger.cs:107
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_CYAN
static readonly String ANSI_BG_CYAN
Select cyan as background color.
Definition: AnsiLogger.cs:89
cs.aworx.lox.loggers.AnsiLogger.ANSI_BG_LIGHT_GRAY
static readonly String ANSI_BG_LIGHT_GRAY
Select light gray as background color.
Definition: AnsiLogger.cs:109