ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
MetaInfo Class Reference

Description:


This class is a sort of plug-in for the TextLogger class. Its purpose is to assemble the meta information of each log line (things like timestamps, thread information, verbosity and domain, etc.).

To manipulate the meta information log output, three options exist:

  • by just changing the Format string (at run-time).
  • by creating a derived class that introduces a new version of method processVariable() to handle one or more format variable differently or to introduce new variables.
  • by creating a derived class that introduces a new version of method Write() to completely control the meta information output.

Definition at line 181 of file textlogger.hpp.

#include <textlogger.hpp>

Collaboration diagram for MetaInfo:
[legend]

Public Field Index:

TickConverter DateConverter
 
String32 DateFormat = A_CHAR("yyyy-MM-dd")
 
AString Format { A_CHAR("%SF:%SL:%A3%SM %A3[%TC +%TL][%tN]%V[%D]%A1#%#: ")}
 
bool FormatWarningOnce = false
 
int LogNumberMinDigits = 3
 
Ticks::Duration MaxElapsedTime
 
NString16 NoMethodInfo = "---"
 
NString16 NoSourceFileInfo = "---"
 
String16 TimeDiffDays = A_CHAR(" days")
 
String16 TimeDiffHours = A_CHAR(" h")
 
String16 TimeDiffMicros = A_CHAR(" \u00B5s")
 
String16 TimeDiffMillis = A_CHAR(" ms")
 
int64_t TimeDiffMinimum =1000L
 
String16 TimeDiffMins = A_CHAR(" m")
 
String16 TimeDiffNanos = A_CHAR(" ns")
 
String16 TimeDiffNone = A_CHAR("--- ")
 
String16 TimeDiffSecs = A_CHAR(" s")
 
String16 TimeElapsedDays = A_CHAR(" Days ")
 
String16 TimeOfDayFormat = A_CHAR("HH:mm:ss")
 
String16 VerbosityError = A_CHAR("[ERR]")
 
String16 VerbosityInfo = A_CHAR(" ")
 
String16 VerbosityVerbose = A_CHAR("[***]")
 
String16 VerbosityWarning = A_CHAR("[WRN]")
 

Public Method Index:

 MetaInfo ()
 
virtual ~MetaInfo ()
 
virtual ALIB_API void Write (TextLogger &logger, AString &buffer, detail::Domain &domain, Verbosity verbosity, ScopeInfo &scope)
 

Field Details:

◆ callerDateTime

lang::system::CalendarDateTime callerDateTime
protected

A singleton calendar time object shared between different format variables during one invocation.

Definition at line 341 of file textlogger.hpp.

◆ DateConverter

TickConverter DateConverter

This field is used to convert the steady and monotonic clock values provided with ScopeInfo::GetTimeStamp into human readable, calendrical values in the moment, field Format contains tokens %TD and/or %TT.

This may become problematic and ambiguous if the system clock is changed during a software run. Especially for long-running background software (daemons, servers, etc.), the software that uses ALox needs to provide a strategy of synchronizing this converter with the system clock.

A simple strategy is to just periodically invoke TickConverter::SyncClocks , for example once a second.

For some explanation of the problem see details of namespace alib::time.

Definition at line 332 of file textlogger.hpp.

◆ DateFormat

String32 DateFormat = A_CHAR("yyyy-MM-dd")

Format string for the output of the log date. For more information, see "Standard Date and Time Format Strings" in .NET StringBuilder.AppendFormat().

Definition at line 261 of file textlogger.hpp.

◆ Format

AString Format { A_CHAR("%SF:%SL:%A3%SM %A3[%TC +%TL][%tN]%V[%D]%A1#%#: ")}

The line format specifies the (automated) log output that is prepended to each log line before the log message itself. This format string can be changed after the creation of a TextLogger.

The string supports replacement variables that begin with a % sign

  • SP: The full path of the source file
  • Sp: The trimmed path of the source file
  • SF: The caller's source file name
  • Sf: The caller's source file name without extension
  • SL: The line number in the source file
  • SM: The method name
  • TD: The date the log call was invoked
  • TT: Time of day the log call was invoked
  • TC: Time elapsed since the Logger was created or its timer was reset
  • TL: Time elapsed since the last log call
  • tN: Thread name
  • tI: Thread ID
  • V: The verbosity. This is replaced by the corresponding strings found in fields VerbosityError, VerbosityWarning, VerbosityInfo and VerbosityVerbose.
  • D: Log domain
  • %#: The log call counter (like a line counter, but counting multi lines as one)
  • An: An auto-adjusted tabulator. This grows whenever it needs, but never shrinks. The optional integer number n specifies how much extra space is added when tab is adjusted. Setting this to a higher value avoids too many adjustments at the beginning of a log session.
  • LG: The name of the Logger. This might be useful if multiple loggers write to the same output stream (e.g. Console).
  • LX: The name of the Lox.
  • P: The name of the process / application.

Defaults to

"%Sp/%SF(%SL):%A5%SM() %A5[%TC +%TL][%tN]%V[%D]%A1(%#): "

If debug logging as well as release logging has scope information disabled (see ALOX_DBG_LOG_CI and ALOX_REL_LOG_CI), then it defaults to: "[%TC +%TL][%tN]%V[%D]%A1(%#): "

Note
The use of %TD and %TT may become problematic and ambiguous if the system clock is changed during a software run. Especially for long-running background software (daemons, servers, etc.), the software that uses ALox needs to provide a strategy of synchronizing the clock with field DateConverter.
For some explanation of the problem see details of namespace alib::time.

Definition at line 234 of file textlogger.hpp.

◆ FormatWarningOnce

bool FormatWarningOnce = false

If false, an one-time warning (using ALIB_WARNING) will be issued if the format string is illegal. With each warning, the flag is set to true to omit further warnings.

Definition at line 244 of file textlogger.hpp.

◆ LogNumberMinDigits

int LogNumberMinDigits = 3

The minimum digits to write for the log number (if used in format string).

Definition at line 304 of file textlogger.hpp.

◆ MaxElapsedTime

Ticks::Duration MaxElapsedTime

The maximum time elapsed. Used to determine the width of the output when writing the elapsed time.

This field will be read from the configuration variable ALOX_LOGGERNAME_MAX_ELAPSED_TIME when the TextLogger that this object belongs to is attached to a Lox and written back on removal.

Definition at line 314 of file textlogger.hpp.

◆ NoMethodInfo

NString16 NoMethodInfo = "---"

Replacement string if no source info is available.

Definition at line 301 of file textlogger.hpp.

◆ NoSourceFileInfo

NString16 NoSourceFileInfo = "---"

Replacement string if no source info is available.

Definition at line 298 of file textlogger.hpp.

◆ TimeDiffDays

String16 TimeDiffDays = A_CHAR(" days")

Format for time difference outputs of more than a day.

Definition at line 295 of file textlogger.hpp.

◆ TimeDiffHours

String16 TimeDiffHours = A_CHAR(" h")

Format for time difference outputs between 1h and 24h.

Definition at line 292 of file textlogger.hpp.

◆ TimeDiffMicros

String16 TimeDiffMicros = A_CHAR(" \u00B5s")

Entity microseconds for time difference outputs below 1000 microseconds.

Definition at line 280 of file textlogger.hpp.

◆ TimeDiffMillis

String16 TimeDiffMillis = A_CHAR(" ms")

Entity milliseconds for time difference outputs below 1000 milliseconds.

Definition at line 283 of file textlogger.hpp.

◆ TimeDiffMinimum

int64_t TimeDiffMinimum =1000L

Minimum time difference to log in nanoseconds. Below that TimeDiffNone is written.

Definition at line 271 of file textlogger.hpp.

◆ TimeDiffMins

String16 TimeDiffMins = A_CHAR(" m")

Format for time difference outputs between 100s and 60 min.

Definition at line 289 of file textlogger.hpp.

◆ TimeDiffNanos

String16 TimeDiffNanos = A_CHAR(" ns")

Entity nanoseconds for time difference outputs below 1000 microsecond.

Definition at line 277 of file textlogger.hpp.

◆ TimeDiffNone

String16 TimeDiffNone = A_CHAR("--- ")

Output for time difference if below reasonable (measurable) minimum defined in TimeDiffMinimum.

Definition at line 274 of file textlogger.hpp.

◆ TimeDiffSecs

String16 TimeDiffSecs = A_CHAR(" s")

Format for time difference outputs between 10s and 99.9s.

Definition at line 286 of file textlogger.hpp.

◆ TimeElapsedDays

String16 TimeElapsedDays = A_CHAR(" Days ")

The word "Days" the out put of time elapsed (if longer than a day).

Definition at line 268 of file textlogger.hpp.

◆ TimeOfDayFormat

String16 TimeOfDayFormat = A_CHAR("HH:mm:ss")

Format string for the output of the time of day. For more information, see "Standard Date and Time Format Strings" in .NET StringBuilder.AppendFormat().

Definition at line 265 of file textlogger.hpp.

◆ VerbosityError

String16 VerbosityError = A_CHAR("[ERR]")

The replacement for variable %V in field Format if Verbosity is Error.

Definition at line 248 of file textlogger.hpp.

◆ VerbosityInfo

String16 VerbosityInfo = A_CHAR(" ")

The replacement for variable %V in field Format if Verbosity is Info.

Definition at line 254 of file textlogger.hpp.

◆ VerbosityVerbose

String16 VerbosityVerbose = A_CHAR("[***]")

The replacement for variable %V in field Format if Verbosity is Verbose.

Definition at line 257 of file textlogger.hpp.

◆ VerbosityWarning

String16 VerbosityWarning = A_CHAR("[WRN]")

The replacement for variable %V in field Format if Verbosity is Warning.

Definition at line 251 of file textlogger.hpp.

Constructor(s) / Destructor Details::

◆ MetaInfo()

MetaInfo ( )
inline

Constructor.

Definition at line 350 of file textlogger.hpp.

◆ ~MetaInfo()

virtual ~MetaInfo ( )
inlinevirtual

Virtual destructor.

Definition at line 355 of file textlogger.hpp.

Method Details:

◆ processVariable()

void processVariable ( TextLogger & logger,
detail::Domain & domain,
Verbosity verbosity,
ScopeInfo & scope,
AString & dest,
Substring & variable )
protectedvirtual

Processes the next command found in the format string, by writing formatted information into the given buffer. The given Substring holds the next command. When method the returns, the command is cut from the front.

Parameters
loggerThe logger that we are embedded in.
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.
scopeInformation about the scope of the Log Statement..
destThe buffer to write meta information into.
variableThe variable to read (may have more characters appended)

Definition at line 160 of file textlogger.cpp.

◆ Write()

void Write ( TextLogger & logger,
AString & buffer,
detail::Domain & domain,
Verbosity verbosity,
ScopeInfo & scope )
virtual

Parses the Format string and logs meta information into the log buffer. For each variable found, method processVariable is invoked. Hence, to add new variables, the latter method can be overwritten by descendants. Overwriting this method is recommended for formatter classes that do not rely on format strings.

Parameters
loggerThe logger that we are embedded in.
bufferThe buffer to write meta information into.
domainThe Log Domain.
verbosityThe verbosity.
scopeInformation about the scope of the Log Statement..

Definition at line 133 of file textlogger.cpp.

◆ writeTimeDiff()

void writeTimeDiff ( AString & buffer,
int64_t diffNanos )
protectedvirtual

Helper function that logs a time given difference into the given buffer in a human readable format. Works from nanoseconds seconds to days.

Parameters
bufferThe buffer to write the time difference representation into.
diffNanosThe time difference to write in nanoseconds.

Definition at line 415 of file textlogger.cpp.


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