#include <textfilelogger.hpp>
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.
Public Fields | |
| aworx::AString | FileName |
| system::SystemErrors | LastSystemError = system::SystemErrors::None |
Public Fields inherited from PlainTextLogger | |
| bool | PruneESCSequences = true |
Public Fields inherited from TextLogger | |
| 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 |
Public Fields inherited from Logger | |
| integer | CntLogs =0 |
| lib::time::Ticks | TimeOfCreation |
| lib::time::Ticks | TimeOfLastLog |
Public Fields inherited from ThreadLock | |
| NCString | DbgOwnerFile =nullptr |
| NCString | DbgOwnerFunc =nullptr |
| int | DbgOwnerLine |
| uint16_t | DbgRecursionWarningThreshold =10 |
| integer | DbgWarningAfterWaitTimeInMillis =2000L |
Public Methods | |
| ALIB_API | TextFileLogger (const aworx::String &fileName, const aworx::NString &loggerName=nullptr) |
| virtual | ~TextFileLogger () override |
Public Methods inherited from TextLogger | |
| 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) |
Public Methods inherited from Logger | |
| virtual | ~Logger () |
| const NString & | GetName () const |
| const NString & | GetTypeName () const |
Public Methods 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) More... | |
| ALIB_API int | RemoveAcquirer (ThreadLock *acquirer) |
Public Methods inherited from ThreadLock | |
| 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 | |
| bool | currentlyInMultiLineOp = false |
| StringWriter | writer |
Protected Fields inherited from TextLogger | |
| AString | logBuf |
| AString | msgBuf |
| std::vector< AString > | replacements |
| int | stdStreamLockRegistrationCounter =0 |
| bool | usesStdStreams |
Protected Fields inherited from Logger | |
| NString32 | Name |
| NString32 | TypeName |
Protected Fields inherited from SmartLock | |
| std::vector< ThreadLock * > | acquirers |
| ThreadLockNR | lock |
Protected Fields inherited from ThreadLock | |
| uint16_t | cntAcquirements =0 |
| std::mutex | mutex |
| std::condition_variable | mutexNotifier |
| std::thread::id | owner |
| Safeness | safeness |
Protected Methods | |
| ALIB_API void | closeFile () |
| virtual ALIB_API integer | logSubstring (const String &buffer, integer start, integer length) override |
| virtual ALIB_API bool | notifyLogOp (Phase phase) override |
| virtual ALIB_API void | notifyMultiLineOp (Phase phase) override |
| ALIB_API void | openFile () |
Protected Methods inherited from PlainTextLogger | |
| PlainTextLogger (const NString &name, const NString &typeName, bool pUsesStdStreams) | |
| virtual | ~PlainTextLogger () override |
| virtual ALIB_API void | logText (detail::Domain &domain, Verbosity verbosity, AString &msg, detail::ScopeInfo &scope, int lineNumber) override |
Protected Methods inherited from TextLogger | |
| ALIB_API | TextLogger (const NString &pName, const NString &typeName, bool pUsesStdStreams) |
Protected Methods inherited from Logger | |
| Logger (const NString &name, const NString &typeName) | |
Additional Inherited Members | |
Public Types inherited from TextLogger | |
| enum | LightColorUsage { Auto, Never, Foreground, Background } |
Public Static Fields inherited from SmartLock | |
| static ALIB_API SmartLock | StdOutputStreams |
|
explicit |
Creates a TextFileLogger.
| fileName | The filename (potentially including a path) of the output log file. |
| loggerName | The name of the Logger. Defaults to "TEXTFILE". |
Definition at line 26 of file textfilelogger.cpp.
|
inlineoverridevirtual |
|
protected |
Closes the file.
Definition at line 67 of file textfilelogger.cpp.
|
overrideprotectedvirtual |
Writes the given region of the given string to the console.
| buffer | The string to write a portion of. |
| start | The start of the portion in buffer to write out. |
| length | The length of the portion in buffer to write out. |
Implements PlainTextLogger.
Definition at line 110 of file textfilelogger.cpp.
|
overrideprotectedvirtual |
Starts/ends log line. Appends a new-line character sequence to previously logged lines.
| phase | Indicates the beginning or end of a log line. |
Implements PlainTextLogger.
Definition at line 92 of file textfilelogger.cpp.
|
overrideprotectedvirtual |
Empty implementation, not needed for this class
| phase | Indicates the beginning or end of a multi-line operation. |
Implements TextLogger.
Definition at line 80 of file textfilelogger.cpp.
|
protected |
Opens the file.
Definition at line 48 of file textfilelogger.cpp.
|
protected |
Flag to prevent file open/close operations when multi line text logging is performed.
Definition at line 50 of file textfilelogger.hpp.
| aworx::AString FileName |
The path and fileName to the log file.
Definition at line 58 of file textfilelogger.hpp.
| system::SystemErrors LastSystemError = system::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.
|
protected |
Encapsulates the text file stream in a system dependent way.
Definition at line 47 of file textfilelogger.hpp.