ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
16 - Colorful Loggers

1. Technical Prerequisites

To explain the use of colorful log output in ALox, it is best to elaborate roughly on some details of the ALox software architecture.

While ALox in principle is designed to process Logables of arbitrary type, the most widely spread use case is logging textual information. For this reason, abstract class Logger (C++, C#, Java) is specialized by class TextLogger (C++, C#, Java) (still abstract). Besides providing basic features useful for textual log output, for example generating human readable meta information of Log Statements, class TextLogger introduces a set of 'escape sequences'. These sequences are gathered in class ESC (C++, C#, Java) which is (for convenience) located in namespace %[com.|cs.]aworx.lox (C++, C#). The ESC-sequences are quite similar to those known from ANSI terminals. They provide settings of foreground and background colors and font styles. The ESC-sequences may occur in the (string type) Logables and as well in field MetaInfo.Format (C++, C#, Java).

This is a sample taken from the documentation of class ESC (C# version):

Log.Info( "The result is: ", ESC.RED, 42 );

Now, if a output 'drain' does not support the modification of colors (e.g. when logging into a text file), these codes need to be removed before the textual log message is written. This task is done by class PlainTextLogger (C++, C#, Java) which in turn specializes TextLogger and which also is still abstract. The following diagram visualizes what was said so far:

The result of this design should not need much explanation: Logger types that do not support colors are derived from PlainTextLogger, while those that support colors are derived from TextLogger:

2. Colorful Logging with ALox

The takeaways from this short technical spotlight are now fairly obvious:

  • The Logables of Log Statements as well as Prefix Logables may contain ESC-sequences.
  • A user of ALox does not need to care about whether Loggers are used that support colorized output (or similar ESC-sequences) or not. They are ignored if not supported.
  • With the introduction of own, ALox-specific escape codes, software that uses ALox becomes independent from the underlying, platform-specific sequences. For example, ALox is not relying on ANSI color codes, which are not supported by colorful Windows consoles. Instead, on each platform, dedicated Loggers will perform the translation of ALox codes to platform-specific ones.
  • A developer of a custom Logger that should not be enabled to support ESC-sequences, simply can derive from class PlainTextLogger which finds and removes ESC-sequences before the messages are passed to the custom type. (For the creation of custom loggers, see also chapter A - Loggers and Implementing Custom Types).

Back to index
Log
lox::Log Log
ESC
lox::ESC ESC