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: "
 
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

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

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

 TextLogger (String name, String typeName, boolean 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)
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ TextLogger()

TextLogger ( String  name,
String  typeName,
boolean  usesStdStreams 
)
protected

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()

int addAcquirer ( ThreadLock  newAcquirer)

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 ( )

Removes all pairs of searched strings and their replacement value.

◆ log()

void log ( Domain  domain,
Verbosity  verbosity,
ArrayList< Object >  logables,
ScopeInfo  scope 
)

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

Reimplemented from Logger.

◆ logText()

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

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 override 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.

Reimplemented in AnsiLogger, PlainTextLogger, and AndroidLogCatLogger.

◆ notifyMultiLineOp()

abstract void notifyMultiLineOp ( Phase  phase)
abstractprotected

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.

Reimplemented in AnsiLogger, ConsoleLogger, AndroidLogCatLogger, TextFileLogger, and MemoryLogger.

◆ removeAcquirer()

int removeAcquirer ( ThreadLock  acquirer)

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 ( )

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 
)

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

AutoSizes autoSizes = new 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.

◆ fmtMultiLineMsgHeadline

String fmtMultiLineMsgHeadline ="ALox: Multi line message follows: "

Headline for multi line messages (depending on multiLineMsgMode) .

◆ 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

MetaInfo metaInfo = new 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

ArrayList<String> replacements = new ArrayList<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

boolean usesStdStreams
protected

Denotes whether this logger writes to the standard output streams.


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