ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Inner Classes | 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 PrintStream 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).

Inner Classes

enum  LightColorUsage
 

Public Static Fields

static final String ANSI_BG_BLACK ="\033[40m"
 Select black as background color.
 
static final String ANSI_BG_BLUE ="\033[44m"
 Select blue as background color.
 
static final String ANSI_BG_CYAN ="\033[46m"
 Select cyan as background color.
 
static final String ANSI_BG_GRAY ="\033[48;5;240m"
 Select gray as background color.
 
static final String ANSI_BG_GREEN ="\033[42m"
 Select green as background color.
 
static final String ANSI_BG_LIGHT_BLUE ="\033[48;5;12m"
 Select light blue as background color.
 
static final String ANSI_BG_LIGHT_CYAN ="\033[48;5;14m"
 Select light cyan as background color.
 
static final String ANSI_BG_LIGHT_GRAY ="\033[48;5;250m"
 Select light gray as background color.
 
static final String ANSI_BG_LIGHT_GREEN ="\033[48;5;10m"
 Select light green as background color.
 
static final String ANSI_BG_LIGHT_MAGENTA ="\033[48;5;13m"
 Select light magenta as background color.
 
static final String ANSI_BG_LIGHT_RED ="\033[48;5;09m"
 Select light red as background color.
 
static final String ANSI_BG_LIGHT_YELLOW ="\033[48;5;11m"
 Select light yellow as background color.
 
static final String ANSI_BG_MAGENTA ="\033[45m"
 Select magenta as background color.
 
static final String ANSI_BG_RED ="\033[41m"
 Select red as background color.
 
static final String ANSI_BG_STD_COL ="\033[49m"
 Select standard background color.
 
static final String ANSI_BG_WHITE ="\033[48;5;15m"
 Select white as background color.
 
static final String ANSI_BG_YELLOW ="\033[43m"
 Select yellow as background color.
 
static final String ANSI_BLACK ="\033[30m"
 Select black as foreground color.
 
static final String ANSI_BLUE ="\033[34m"
 Select blue as foreground color.
 
static final String ANSI_BOLD ="\033[1m"
 Select bold font style.
 
static final String ANSI_CYAN ="\033[36m"
 Select cyan as foreground color.
 
static final String ANSI_GRAY ="\033[38;5;240m"
 Select gray as foreground color.
 
static final String ANSI_GREEN ="\033[32m"
 Select green as foreground color.
 
static final String ANSI_ITALICS ="\033[3m"
 Select italics font style.
 
static final String ANSI_LIGHT_BLUE ="\033[38;5;12m"
 Select light blue as foreground color.
 
static final String ANSI_LIGHT_CYAN ="\033[38;5;14m"
 Select light cyan as foreground color.
 
static final String ANSI_LIGHT_GRAY ="\033[38;5;250m"
 Select light gray as foreground color.
 
static final String ANSI_LIGHT_GREEN ="\033[38;5;10m"
 Select light green as foreground color.
 
static final String ANSI_LIGHT_MAGENTA ="\033[38;5;13m"
 Select light magenta as foreground color.
 
static final String ANSI_LIGHT_RED ="\033[38;5;09m"
 Select light red as foreground color.
 
static final String ANSI_LIGHT_YELLOW ="\033[38;5;11m"
 Select light yellow as foreground color.
 
static final String ANSI_MAGENTA ="\033[35m"
 Select magenta as foreground color.
 
static final String ANSI_RED ="\033[31m"
 Select red as foreground color.
 
static final String ANSI_RESET ="\033[0m"
 Reset colors and font style.
 
static final String ANSI_STD_COL ="\033[39m"
 Select standard foreground color.
 
static final String ANSI_STD_STYLE ="\033[0m"
 Select standard font style.
 
static final String ANSI_WHITE ="\033[38;5;15m"
 Select white as foreground color.
 
static final String ANSI_YELLOW ="\033[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: "
 
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()
 
Ticks timeOfLastLog = new Ticks()
 
- Public Fields inherited from ThreadLock
int recursionWarningThreshold = 10
 
int waitWarningTimeLimitInMillis = 1000
 

Public Methods

 AnsiLogger (PrintStream out, boolean usesStdStreams)
 
 AnsiLogger (PrintStream out, boolean usesStdStreams, String name)
 
 AnsiLogger (PrintStream out, boolean usesStdStreams, String name, String typeName)
 
- Public Methods inherited from TextLogger
int addAcquirer (ThreadLock newAcquirer)
 
void clearReplacements ()
 
void log (Domain domain, Verbosity verbosity, ArrayList< Object > logables, ScopeInfo scope)
 
int removeAcquirer (ThreadLock acquirer)
 
void resetAutoSizes ()
 
void setReplacement (String searched, String replacement)
 
- Public Methods inherited from Logger
String getName ()
 
String getTypeName ()
 
String toString ()
 
- Public Methods inherited from SmartLock
 SmartLock ()
 
int cntAcquirers ()
 
- Public Methods inherited from ThreadLock
 ThreadLock ()
 
 ThreadLock (LockMode lockMode)
 
 ThreadLock (LockMode lockMode, Safeness safeness)
 
void acquire ()
 
int dbgCountAcquirements (Thread thread)
 
LockMode getMode ()
 
Safeness getSafeness ()
 
void release ()
 
void setSafeness (Safeness safeness)
 
boolean willRelease ()
 

Protected Fields

String[] ansiCols
 
PrintStream out
 
- Protected Fields inherited from TextLogger
AString logBuf = new AString( 256 )
 
AString msgBuf = new AString( 128 )
 
ArrayList< String > replacements = new ArrayList<String>()
 
int stdStreamLockRegistrationCounter =0
 
boolean usesStdStreams
 
- Protected Fields inherited from Logger
String name
 
String typeName
 
- Protected Fields inherited from SmartLock
ArrayList< ThreadLockacquirers = new ArrayList<ThreadLock>()
 
- Protected Fields inherited from ThreadLock
int cntAcquirements
 
boolean createOwnerStackTrace = false
 
LockMode lockMode
 
Object mutex
 
Thread owner
 
Exception ownerException
 
Ticks waitTime = new Ticks()
 

Protected Methods

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

Additional Inherited Members

- Package Access Methods inherited from ThreadLock
void constructor (LockMode lockMode, Safeness safeness)
 

Constructor & Destructor Documentation

◆ AnsiLogger() [1/3]

AnsiLogger ( PrintStream  out,
boolean  usesStdStreams,
String  name,
String  typeName 
)

Creates an AnsiLogger with the given PrintStream and name.

Parameters
outA java.io.PrintStream to write the log data to.
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".

◆ AnsiLogger() [2/3]

AnsiLogger ( PrintStream  out,
boolean  usesStdStreams,
String  name 
)

Creates an AnsiLogger with the given PrintStream and name.

Parameters
outA java.io.PrintStream to write the log data to.
usesStdStreamsDenotes whether this logger writes to the standard output streams.
nameThe name of the Logger. Defaults to "ANSI".

◆ AnsiLogger() [3/3]

AnsiLogger ( PrintStream  out,
boolean  usesStdStreams 
)

Overwritten constructor providing default parameters.

Parameters
outA java.io.PrintStream to write the log data to.
usesStdStreamsDenotes whether this logger writes to the standard output streams.

Member Function Documentation

◆ construct()

void construct ( PrintStream  ps)
protected

Helper method used by the constructors.

Parameters
psA java.io.PrintStream to write the log data to.

◆ logText()

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

Implementation of the abstract method of parent class TextLogger. Logs messages to the application console.

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.

Reimplemented from TextLogger.

◆ notifyMultiLineOp()

void notifyMultiLineOp ( Phase  phase)
protected

Empty implementation.

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

Reimplemented from TextLogger.

Member Data Documentation

◆ ansiCols

String [] ansiCols
protected

◆ out

PrintStream out
protected

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