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

Class Description


This class is a still abstract implementation of class Logger which is used as the super class for all textual Logger implementations within ALox, e.g. ConsoleLogger.

The class uses two helper classes. One to convert the log message object into a string representation and a second to generate the textual representation of the meta information of a log call. These helpers can be extended and replaced to modify the behavior of TextLogger.

The final log message is then passed to the abstract method logText(). Hence, custom Logger classes that inherited from this class instead of directly from class Logger, need to implement logText() instead of implementing Log.

Class TextLogger supports multi line log outputs. Such multi line log outputs can be configured to be logged in different ways. See MultiLineMsgMode for more information.

Public Fields

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

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

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

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

Constructor & Destructor Documentation

◆ TextLogger()

TextLogger ( String  name,
String  typeName,
bool  usesStdStreams 
)
inlineprotected

Constructs a TextLogger.

Parameters
nameThe name of the Logger. If empty, it defaults to the type name.
typeNameThe type of the Logger.
usesStdStreamsDenotes whether this logger writes to the standard output streams.

Member Function Documentation

◆ AddAcquirer()

override int AddAcquirer ( ThreadLock  newAcquirer)
inlinevirtual

Invokes grand-parent's method and in addition, if field usesStdStreams is set, registers with ALIB.StdOutputStreamsLock.

Parameters
newAcquirerThe acquirer to add.
Returns
The new number of acquirers set.

Reimplemented from SmartLock.

◆ ClearReplacements()

void ClearReplacements ( )
inline

Removes all pairs of searched strings and their replacement value.

◆ Log()

override void Log ( Domain  domain,
Verbosity  verbosity,
List< Object >  logables,
ScopeInfo  scope 
)
inlinevirtual

This is the implementation of the abstract method inherited from class Logger that executes a log.
This class implements this method and but exposes the new abstract method logText. This mechanism allows this class to do various things that are standard to Loggers of type TextLogger. For example, meta information of the log invocation is formatted and string replacements are performed. This way, descendants of this class will consume a ready to use log buffer with all meta information and contents of all objects to be included and their primary obligation is to copy the content into a corresponding output stream.

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.
logablesThe list of objects to log.
scopeInformation about the scope of the Log Statement..

Implements Logger.

◆ logText()

abstract void logText ( Domain  domain,
Verbosity  verbosity,
AString  msg,
ScopeInfo  scope,
int  lineNumber 
)
protectedpure virtual

This abstract method introduced by this class "replaces" the abstract method Log of parent class Logger which this class implements. In other words, descendants of this class need to overwrite this method instead of Log. This class TextLogger is responsible for generating meta information, doing text replacements, handle multi-line messages, etc. and provides the textual representation of the whole log contents to descendants using this method.

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.

Implemented in AnsiLogger, ColorConsoleLogger, and PlainTextLogger.

◆ notifyMultiLineOp()

abstract void notifyMultiLineOp ( Phase  phase)
protectedpure virtual

Abstract method to be implemented by descendants. This message is called only when multi-line messages are logged. It is called exactly once before a series of logText calls of a multi-line message and exactly once after such series.
This is useful if the writing of text includes the acquisition of system resources (e.g. opening a file).

Parameters
phaseIndicates the beginning or end of a multi-line operation.

Implemented in AnsiLogger, ColorConsoleLogger, TextFileLogger, CLRDebuggerLogger, ConsoleLogger, and MemoryLogger.

◆ RemoveAcquirer()

override int RemoveAcquirer ( ThreadLock  acquirer)
inlinevirtual

Invokes grand-parent's method and in addition, de-registers with ALIB.StdOutputStreamsLock.

Parameters
acquirerThe acquirer to remove.
Returns
The new number of acquirers set.

Reimplemented from SmartLock.

◆ ResetAutoSizes()

void ResetAutoSizes ( )
inline

Resets automatically widened tab stops and field widths of this logger by calling ResetAutoSizes on field Converter.

Note
The sizes affected are the ones used to format the custom log output, not the ones uses for the meta information. To reset the auto-sizes of the meta information, invoke AutoSizes::Reset on field AutoSizes.

◆ SetReplacement()

void SetReplacement ( String  searched,
String  replacement 
)
inline

Adds the given pair of replacement strings. If searched string already exists, the current replacement string gets replaced. If the replacement string is null, nothing is set and a previously set replacement definition becomes unset.

Parameters
searchedThe string to be searched.
replacementThe replacement string. If this equals null a previously set replacement will be unset.

Member Data Documentation

◆ AutoSizes

Holds a list of values for auto tab positions and field sizes. For each requested value, a corresponding array field is created on the fly. If the format string get's changed and different (new) auto values should be used, then this field should be reset after setting the new format string. The other way round, it is also possible to preset set minimum values for tabs and field sizes and hence avoid the columns growing during the lifetime of the Logger.

This field will be read from the configuration variable ALOX_LOGGERNAME_AUTO_SIZES when the TextLogger that we belong to is attached to a Lox and written back on removal.

◆ Converter

ObjectConverter Converter

A helper object to get textual representation of logable objects. If no converter is set when this logger is attached to a lox, a converter of type StandardConverter is created and used. Custom loggers might create their own, custom converter objects here.

To extend class TextLogger to support logging custom objects, custom converters can set. The preferred alternative is however, to make custom types be formattable by formatter classes used with StandardConverter.

◆ FmtMsgSuffix

String FmtMsgSuffix =""

Characters written after each Log Statement. This may be used for example to reset colors and styles. Note, that with multi-line Log Statements, the contents of this field is not written at the end of each line, but only at the end of the last line. To define characters that are written after each line of a multi-line Log Statement, field FmtMultiLineSuffix.

Defaults to empty string.

◆ FmtMultiLinePrefix

String FmtMultiLinePrefix =">> "

Prefix for multi line messages. This is also used if multi line messages logging is switched off (MultiLineMsgMode == 0) but replacing of a set MultiLineDelimiter takes place.

◆ FmtMultiLineSuffix

String FmtMultiLineSuffix =null

Suffix for multi line messages. This is also used if multi line messages logging is switched off (MultiLineMsgMode == 0) and replacing of a set MultiLineDelimiter takes place.
Note that at the end of the last line, in addition FmtMsgSuffix is added.
Defaults to "".

◆ logBuf

AString logBuf =new AString( 256 )
protected

The internal log Buffer.

◆ MetaInfo

A helper object to format log objects into textual representations. This class incorporates a format string that defines the meta information in the log output. Furthermore, to extend TextLogger, this object can be replaced by custom implementations of it.

◆ msgBuf

AString msgBuf =new AString( 128 )
protected

A buffer for converting the user object(s)

◆ MultiLineDelimiter

String MultiLineDelimiter =null

This is the string interpreted as line delimiter within log messages. If nulled, then '\n', '\r' or '\r\n' is recognized.
Important: Can be set to an empty string, to stop any multi line processing of TextLogger, even the replacements of the delimiter character.

◆ MultiLineDelimiterRepl

String MultiLineDelimiterRepl ="\\r"

This is the readable (!) separator string, for logging out multi line messages into a single line (MultiLineMsgMode==0).

◆ MultiLineMsgMode

int MultiLineMsgMode =2

Determines if multi line messages should be split into different log lines. Possible values are:

  • 0: No line split is performed, delimiters can be replaced by readable delimiters (depending on setting of MultiLineDelimiter and # MultiLineDelimiterRepl).
  • 1: Each log line contains all meta information
  • 2: Starting with second log line, meta information is replaced by blanks (default)
  • 3: The headline FmtMultiLineMsgHeadline is logged and all lines of the multi line text are logged at position zero (without further meta information)
  • 4: Just the multi line text is logged, starting at column zero (no meta information is logged)

◆ replacements

List<String> replacements =new List<String>()
protected

A list of pairs of strings. Within each log message, the first string of a pair is searched and replaced by the second string. Very simple, but useful in some cases.

◆ stdStreamLockRegistrationCounter

int stdStreamLockRegistrationCounter =0
protected

Used to avoid to repeatedly register with ALib standard output stream lockers when attached to multiple instances of class Lox.

◆ usesStdStreams

bool usesStdStreams
protected

Denotes whether this logger writes to the standard output streams.


The documentation for this class was generated from the following file: