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

Description:


This is a very simple file logger for textual log outputs. The file name string provided in the constructor is not verified. The fileName may be changed by simply setting the public member FileName.

In alignment with ALox principles (ALox does not throw!), the logger does not throw i/o exceptions. In debug-compilations, ALib warnings are issued. Recent system io/ errors are stored in public field# LastSystemError. The constructor tries to open/close the file with write permissions. For many applications, it should be enough to check this field after construction and take according actions on failure. Otherwise, errors may periodically be checked by an application (e.g. no space left on device, etc.).

Definition at line 39 of file textfilelogger.hpp.

#include <textfilelogger.hpp>

Inheritance diagram for TextFileLogger:
[legend]
Collaboration diagram for TextFileLogger:
[legend]

Public Field Index:

alib::AString FileName
 
SystemErrors LastSystemError = SystemErrors::None
 
- Public Field Index: inherited from PlainTextLogger
bool PruneESCSequences = true
 
- Public Field Index: inherited from TextLogger
strings::util::AutoSizes AutoSizes
 
ObjectConverterConverter = nullptr
 
String16 FmtMsgSuffix
 
String64 FmtMultiLineMsgHeadline = A_CHAR("ALox: Multi line message follows: ")
 
String16 FmtMultiLinePrefix = A_CHAR(">> ")
 
String16 FmtMultiLineSuffix = A_CHAR("")
 
textlogger::MetaInfoMetaInfo
 
AString MultiLineDelimiter
 
String16 MultiLineDelimiterRepl = A_CHAR("\\r")
 
int MultiLineMsgMode =2
 
- Public Field Index: inherited from Logger
integer CntLogs =0
 
time::Ticks TimeOfCreation
 
time::Ticks TimeOfLastLog
 
- Public Field Index: inherited from ThreadLock
NCString DbgOwnerFile =nullptr
 
NCString DbgOwnerFunc =nullptr
 
int DbgOwnerLine
 
uint16_t DbgRecursionWarningThreshold =10
 
integer DbgWarningAfterWaitTimeInMillis =2000L
 

Public Method Index:

ALIB_API TextFileLogger (const alib::String &fileName, const alib::NString &loggerName=nullptr)
 
virtual ~TextFileLogger () override
 
- Public Method Index: inherited from TextLogger
virtual ALIB_API ~TextLogger () override
 
virtual ALIB_API void AcknowledgeLox (LoxImpl *lox, lang::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)
 
- Public Method Index: inherited from Logger
virtual ~Logger ()
 
const NStringGetName () const
 
const NStringGetTypeName () const
 
- Public Method Index: inherited from SmartLock
 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)
 
ALIB_API int RemoveAcquirer (ThreadLock *acquirer)
 
- Public Method Index: inherited from ThreadLock
ALIB_API ThreadLock (lang::Safeness safeness=lang::Safeness::Safe)
 
ALIB_API ~ThreadLock ()
 
ALIB_API void Acquire (const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
 
int CountAcquirements () const
 
ThreadGetOwner () const
 
lang::Safeness GetSafeness () const
 
bool IsOwnedByCurrentThread () const
 
ALIB_API void Release ()
 defined(ALIB_DOX)
 
ALIB_API void SetSafeness (lang::Safeness safeness)
 
bool WillRelease () const
 

Additional Inherited Members

- Public Type Index: inherited from TextLogger
enum class  LightColorUsage { Auto , Never , Foreground , Background }
 
- Public Static Field Index: inherited from SmartLock
static ALIB_API SmartLock StdOutputStreams
 

Field Details:

◆ currentlyInMultiLineOp

bool currentlyInMultiLineOp = false
protected

Flag to prevent file open/close operations when multi line text logging is performed.

Definition at line 50 of file textfilelogger.hpp.

◆ FileName

alib::AString FileName

The path and fileName to the log file.

Definition at line 58 of file textfilelogger.hpp.

◆ LastSystemError

SystemErrors LastSystemError = SystemErrors::None

Errors that usually indicate i/o problems. With construction of the logger, the file is tried to be opened and closed, which might indicate major problems (permissions, path, etc) with this public field very early.

Definition at line 63 of file textfilelogger.hpp.

◆ writer

StringWriter writer
protected

Encapsulates the text file stream in a system dependent way.

Definition at line 47 of file textfilelogger.hpp.

Constructor(s) / Destructor Details::

◆ TextFileLogger()

TextFileLogger ( const alib::String & fileName,
const alib::NString & loggerName = nullptr )
explicit

Creates a TextFileLogger.

Parameters
fileNameThe filename (potentially including a path) of the output log file.
loggerNameThe name of the Logger. Defaults to "TEXTFILE".

Definition at line 26 of file textfilelogger.cpp.

◆ ~TextFileLogger()

virtual ~TextFileLogger ( )
inlineoverridevirtual

Destructs a TextFileLogger

Definition at line 82 of file textfilelogger.hpp.

Method Details:

◆ closeFile()

void closeFile ( )
protected

Closes the file.

Definition at line 67 of file textfilelogger.cpp.

Here is the call graph for this function:

◆ logSubstring()

integer logSubstring ( const String & buffer,
integer start,
integer length )
overrideprotectedvirtual

Writes the given region of the given string to the console.

Parameters
bufferThe string to write a portion of.
startThe start of the portion in buffer to write out.
lengthThe length of the portion in buffer to write out.
Returns
The number of characters written, -1 on error.

Implements PlainTextLogger.

Definition at line 110 of file textfilelogger.cpp.

Here is the call graph for this function:

◆ notifyLogOp()

bool notifyLogOp ( lang::Phase phase)
overrideprotectedvirtual

Starts/ends log line. Appends a new-line character sequence to previously logged lines.

Parameters
phaseIndicates the beginning or end of a log line.
Returns
Always returns true.

Implements PlainTextLogger.

Definition at line 92 of file textfilelogger.cpp.

Here is the call graph for this function:

◆ notifyMultiLineOp()

void notifyMultiLineOp ( lang::Phase phase)
overrideprotectedvirtual

Empty implementation, not needed for this class

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

Implements TextLogger.

Definition at line 80 of file textfilelogger.cpp.

Here is the call graph for this function:

◆ openFile()

void openFile ( )
protected

Opens the file.

Definition at line 48 of file textfilelogger.cpp.

Here is the call graph for this function:

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