#include <ansilogger.hpp>
A logger that logs all messages to the std::basic_ostream 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).
Definition at line 67 of file ansilogger.hpp.
Public Static Fields | |
static ALIB_API character | ANSI_BG_BLACK [6] { A_CHAR("\033[40m") } |
Select black as background color. | |
static ALIB_API character | ANSI_BG_BLUE [6] { A_CHAR("\033[44m") } |
Select blue as background color. | |
static ALIB_API character | ANSI_BG_CYAN [6] { A_CHAR("\033[46m") } |
Select cyan as background color. | |
static ALIB_API character | ANSI_BG_GRAY [12] { A_CHAR("\033[48;5;240m") } |
Select gray as background color. | |
static ALIB_API character | ANSI_BG_GREEN [6] { A_CHAR("\033[42m") } |
Select green as background color. | |
static ALIB_API character | ANSI_BG_LIGHT_BLUE [11] { A_CHAR("\033[48;5;12m") } |
Select light blue as background color. | |
static ALIB_API character | ANSI_BG_LIGHT_CYAN [11] { A_CHAR("\033[48;5;14m") } |
Select light cyan as background color. | |
static ALIB_API character | ANSI_BG_LIGHT_GRAY [12] { A_CHAR("\033[48;5;250m") } |
Select light gray as background color. | |
static ALIB_API character | ANSI_BG_LIGHT_GREEN [11] { A_CHAR("\033[48;5;10m") } |
Select light green as background color. | |
static ALIB_API character | ANSI_BG_LIGHT_MAGENTA [11] { A_CHAR("\033[48;5;13m") } |
Select light magenta as background color. | |
static ALIB_API character | ANSI_BG_LIGHT_RED [11] { A_CHAR("\033[48;5;09m") } |
Select light red as background color. | |
static ALIB_API character | ANSI_BG_LIGHT_STD_COL [6] { A_CHAR("\033[49m") } |
Select standard background color. | |
static ALIB_API character | ANSI_BG_LIGHT_YELLOW [11] { A_CHAR("\033[48;5;11m") } |
Select light yellow as background color. | |
static ALIB_API character | ANSI_BG_MAGENTA [6] { A_CHAR("\033[45m") } |
Select magenta as background color. | |
static ALIB_API character | ANSI_BG_RED [6] { A_CHAR("\033[41m") } |
Select red as background color. | |
static ALIB_API character | ANSI_BG_STD_COL [6] { A_CHAR("\033[49m") } |
Select standard background color. | |
static ALIB_API character | ANSI_BG_WHITE [11] { A_CHAR("\033[48;5;15m") } |
Select white as background color. | |
static ALIB_API character | ANSI_BG_YELLOW [6] { A_CHAR("\033[43m") } |
Select yellow as background color. | |
static ALIB_API character | ANSI_BLACK [6] { A_CHAR("\033[30m") } |
Select black as foreground color. | |
static ALIB_API character | ANSI_BLUE [6] { A_CHAR("\033[34m") } |
Select blue as foreground color. | |
static ALIB_API character | ANSI_BOLD [5] { A_CHAR("\033[1m") } |
Select bold font style. | |
static ALIB_API character | ANSI_CYAN [6] { A_CHAR("\033[36m") } |
Select cyan as foreground color. | |
static ALIB_API character | ANSI_GRAY [12] { A_CHAR("\033[38;5;240m") } |
Select gray as foreground color. | |
static ALIB_API character | ANSI_GREEN [6] { A_CHAR("\033[32m") } |
Select green as foreground color. | |
static ALIB_API character | ANSI_ITALICS [5] { A_CHAR("\033[3m") } |
Select italics font style. | |
static ALIB_API character | ANSI_LIGHT_BLUE [11] { A_CHAR("\033[38;5;12m") } |
Select light blue as foreground color. | |
static ALIB_API character | ANSI_LIGHT_CYAN [11] { A_CHAR("\033[38;5;14m") } |
Select light cyan as foreground color. | |
static ALIB_API character | ANSI_LIGHT_GRAY [12] { A_CHAR("\033[38;5;250m") } |
Select light gray as foreground color. | |
static ALIB_API character | ANSI_LIGHT_GREEN [11] { A_CHAR("\033[38;5;10m") } |
Select light green as foreground color. | |
static ALIB_API character | ANSI_LIGHT_MAGENTA [11] { A_CHAR("\033[38;5;13m") } |
Select light magenta as foreground color. | |
static ALIB_API character | ANSI_LIGHT_RED [11] { A_CHAR("\033[38;5;09m") } |
Select light red as foreground color. | |
static ALIB_API character | ANSI_LIGHT_STD_COL [6] { A_CHAR("\033[39m") } |
Select standard foreground color. | |
static ALIB_API character | ANSI_LIGHT_YELLOW [11] { A_CHAR("\033[38;5;11m") } |
Select light yellow as foreground color. | |
static ALIB_API character | ANSI_MAGENTA [6] { A_CHAR("\033[35m") } |
Select magenta as foreground color. | |
static ALIB_API character | ANSI_RED [6] { A_CHAR("\033[31m") } |
Select red as foreground color. | |
static ALIB_API character | ANSI_RESET [5] { A_CHAR("\033[0m") } |
Reset colors and font style. | |
static ALIB_API character | ANSI_STD_COL [6] { A_CHAR("\033[39m") } |
Select standard foreground color. | |
static ALIB_API character | ANSI_STD_STYLE [5] { A_CHAR("\033[0m") } |
Select standard font style. | |
static ALIB_API character | ANSI_WHITE [11] { A_CHAR("\033[38;5;15m") } |
Select white as foreground color. | |
static ALIB_API character | ANSI_YELLOW [6] { A_CHAR("\033[33m") } |
Select yellow as foreground color. | |
![]() | |
static ALIB_API SmartLock | StdOutputStreams |
Public Fields | |
LightColorUsage | UseLightColors |
![]() | |
lib::strings::util::AutoSizes | AutoSizes |
ObjectConverter * | Converter = nullptr |
String16 | FmtMsgSuffix |
String64 | FmtMultiLineMsgHeadline = A_CHAR("ALox: Multi line message follows: ") |
String16 | FmtMultiLinePrefix = A_CHAR(">> ") |
String16 | FmtMultiLineSuffix = A_CHAR("") |
textlogger::MetaInfo * | MetaInfo |
AString | MultiLineDelimiter |
String16 | MultiLineDelimiterRepl = A_CHAR("\\r") |
int | MultiLineMsgMode =2 |
![]() | |
integer | CntLogs =0 |
lib::time::Ticks | TimeOfCreation |
lib::time::Ticks | TimeOfLastLog |
![]() | |
NCString | DbgOwnerFile =nullptr |
NCString | DbgOwnerFunc =nullptr |
int | DbgOwnerLine |
uint16_t | DbgRecursionWarningThreshold =10 |
integer | DbgWarningAfterWaitTimeInMillis =2000L |
Public Methods | |
ALIB_API | AnsiLogger (const NString &name=nullptr, const NString &typeName="ANSI") |
ALIB_API | AnsiLogger (std::ostream *pOStream, const NString &name=nullptr, const NString &typeName="ANSI") |
virtual ALIB_API | ~AnsiLogger () override |
![]() | |
virtual ALIB_API | ~TextLogger () override |
virtual ALIB_API void | AcknowledgeLox (LoxImpl *lox, ContainerOp op) override |
virtual ALIB_API void | ClearReplacements () |
virtual ALIB_API void | Log (Domain &domain, Verbosity verbosity, Boxes &logables, ScopeInfo &scope) override |
virtual ALIB_API void | ResetAutoSizes () |
virtual ALIB_API void | SetReplacement (const String &searched, const String &replacement) |
![]() | |
virtual | ~Logger () |
const NString & | GetName () const |
const NString & | GetTypeName () const |
![]() | |
SmartLock () | |
void | Acquire (const NCString &dbgFile, int dbgLine, const NCString &dbgFunc) |
ALIB_API int | AddAcquirer (ThreadLock *newAcquirer) |
ALIB_API int | CntAcquirers () |
ALIB_API void | Release () |
defined(ALIB_DOX) More... | |
ALIB_API int | RemoveAcquirer (ThreadLock *acquirer) |
![]() | |
ALIB_API | ThreadLock (Safeness safeness=Safeness::Safe) |
ALIB_API | ~ThreadLock () |
ALIB_API void | Acquire (const NCString &dbgFile, int dbgLine, const NCString &dbgFunc) |
int | CountAcquirements () const |
Thread * | GetOwner () const |
Safeness | GetSafeness () const |
bool | IsOwnedByCurrentThread () const |
ALIB_API void | Release () |
defined(ALIB_DOX) More... | |
ALIB_API void | SetSafeness (Safeness safeness) |
bool | WillRelease () const |
Protected Fields | |
StringWriter | writer |
![]() | |
AString | logBuf |
AString | msgBuf |
std::vector< AString > | replacements |
int | stdStreamLockRegistrationCounter =0 |
bool | usesStdStreams |
![]() | |
NString32 | Name |
NString32 | TypeName |
![]() | |
std::vector< ThreadLock * > | acquirers |
ThreadLockNR | lock |
![]() | |
uint16_t | cntAcquirements =0 |
std::mutex | mutex |
std::condition_variable | mutexNotifier |
std::thread::id | owner |
Safeness | safeness |
Protected Methods | |
ALIB_API void | construct () |
virtual ALIB_API void | logText (detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber) override |
virtual void | notifyMultiLineOp (Phase) override |
![]() | |
ALIB_API | TextLogger (const NString &pName, const NString &typeName, bool pUsesStdStreams) |
![]() | |
Logger (const NString &name, const NString &typeName) | |
Additional Inherited Members | |
![]() | |
enum | LightColorUsage { Auto, Never, Foreground, Background } |
|
explicit |
Creates an AnsiLogger using std::cout
respectively std::wcout
.
name | The name of the Logger, defaults to what is provided with parameter typeName. |
typeName | The type of the Logger, defaults to "ANSI". |
Definition at line 141 of file ansilogger.cpp.
|
explicit |
Creates an AnsiLogger using the given output stream.
std::cout
respectively std::wcout
must not be provided here. Instead, the alternative constructor omitting parameter pOStream is to be used. pOStream | The output stream to write into. |
name | The name of the Logger, defaults to what is provided with parameter typeName. |
typeName | The type of the Logger, defaults to "ANSI". |
Definition at line 147 of file ansilogger.cpp.
|
overridevirtual |
|
protected |
The shared pared of the constructor.
Definition at line 156 of file ansilogger.cpp.
|
overrideprotectedvirtual |
Implementation of the abstract method of parent class TextLogger. Logs messages to the basic output stream provided in the constructor. Replaces ALox ESC escape sequences with ANSI escape sequences.
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.
Definition at line 201 of file ansilogger.cpp.
|
inlineoverrideprotectedvirtual |
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 .
Definition at line 206 of file ansilogger.hpp.
|
protected |
Encapsulates std::cout
, std::wcout
or the output stream provided in the corresponding constructor.
Definition at line 179 of file ansilogger.hpp.