ALox
V. 2402 R. 0
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).
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.
AnsiLogger (System.IO.TextWriter textWriter , bool usesStdStreams , String name=null, String typeName="ANSI")
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)
String GetName ()
String GetTypeName ()
override String ToString ()
SmartLock ()
int CntAcquirers ()
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 ()
◆ LightColorUsage
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.
◆ AnsiLogger()
AnsiLogger
(
System.IO.TextWriter
textWriter ,
bool
usesStdStreams ,
String
name = null
,
String
typeName = "ANSI"
)
inline
Creates an AnsiLogger .
Parameters
textWriter The TextWriter object to write into.
usesStdStreams Denotes whether this logger writes to the standard output streams .
name The name of the Logger , defaults to what is provided with parameter typeName .
typeName The type of the Logger , defaults to "ANSI".
◆ logText()
Implementation of the abstract method of parent class TextLogger. Logs messages to the application console and/or the VStudio output window.
Parameters
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 .
◆ notifyMultiLineOp()
override void notifyMultiLineOp
(
Phase
phase )
inline protected virtual
Empty implementation.
Parameters
phase The phase of the multi-line operation (ignored).
Implements TextLogger .
◆ ansiCols
Initial value: Internal table used to convert ESC colors to ANSI colors
◆ textWriter
System.IO.TextWriter textWriter
protected
The TextWriter provided in the constructor.
◆ 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:
static readonly String ANSI_BG_LIGHT_CYAN
Select light cyan as background color.
Definition: AnsiLogger.cs:108
static readonly String ANSI_BG_RED
Select red as background color.
Definition: AnsiLogger.cs:84
static readonly String ANSI_BG_LIGHT_YELLOW
Select light yellow as background color.
Definition: AnsiLogger.cs:105
static readonly String ANSI_GREEN
Select green as foreground color.
Definition: AnsiLogger.cs:74
static readonly String ANSI_BG_WHITE
Select white as background color.
Definition: AnsiLogger.cs:91
static readonly String ANSI_LIGHT_GRAY
Select light gray as foreground color.
Definition: AnsiLogger.cs:101
static readonly String ANSI_CYAN
Select cyan as foreground color.
Definition: AnsiLogger.cs:78
static readonly String ANSI_BG_STD_COL
Select standard background color.
Definition: AnsiLogger.cs:93
static readonly String ANSI_LIGHT_GREEN
Select light green as foreground color.
Definition: AnsiLogger.cs:96
static readonly String ANSI_YELLOW
Select yellow as foreground color.
Definition: AnsiLogger.cs:75
static readonly String ANSI_WHITE
Select white as foreground color.
Definition: AnsiLogger.cs:80
static readonly String ANSI_BG_LIGHT_BLUE
Select light blue as background color.
Definition: AnsiLogger.cs:106
static readonly String ANSI_BLACK
Select black as foreground color.
Definition: AnsiLogger.cs:79
static readonly String ANSI_BG_BLACK
Select black as background color.
Definition: AnsiLogger.cs:90
static readonly String ANSI_BG_BLUE
Select blue as background color.
Definition: AnsiLogger.cs:87
static readonly String ANSI_RED
Select red as foreground color.
Definition: AnsiLogger.cs:73
static readonly String ANSI_LIGHT_YELLOW
Select light yellow as foreground color.
Definition: AnsiLogger.cs:97
static readonly String ANSI_BG_GRAY
Select gray as background color.
Definition: AnsiLogger.cs:92
static readonly String ANSI_STD_COL
Select standard foreground color.
Definition: AnsiLogger.cs:82
static readonly String ANSI_BG_YELLOW
Select yellow as background color.
Definition: AnsiLogger.cs:86
static readonly String ANSI_MAGENTA
Select magenta as foreground color.
Definition: AnsiLogger.cs:77
static readonly String ANSI_BG_LIGHT_RED
Select light red as background color.
Definition: AnsiLogger.cs:103
static readonly String ANSI_BG_GREEN
Select green as background color.
Definition: AnsiLogger.cs:85
static readonly String ANSI_LIGHT_MAGENTA
Select light magenta as foreground color.
Definition: AnsiLogger.cs:99
static readonly String ANSI_BLUE
Select blue as foreground color.
Definition: AnsiLogger.cs:76
static readonly String ANSI_LIGHT_BLUE
Select light blue as foreground color.
Definition: AnsiLogger.cs:98
static readonly String ANSI_GRAY
Select gray as foreground color.
Definition: AnsiLogger.cs:81
static readonly String ANSI_BG_MAGENTA
Select magenta as background color.
Definition: AnsiLogger.cs:88
static readonly String ANSI_LIGHT_CYAN
Select light cyan as foreground color.
Definition: AnsiLogger.cs:100
static readonly String ANSI_BG_LIGHT_GREEN
Select light green as background color.
Definition: AnsiLogger.cs:104
static readonly String ANSI_LIGHT_RED
Select light red as foreground color.
Definition: AnsiLogger.cs:95
static readonly String ANSI_BG_LIGHT_MAGENTA
Select light magenta as background color.
Definition: AnsiLogger.cs:107
static readonly String ANSI_BG_CYAN
Select cyan as background color.
Definition: AnsiLogger.cs:89
static readonly String ANSI_BG_LIGHT_GRAY
Select light gray as background color.
Definition: AnsiLogger.cs:109