ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
textfilelogger.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_alox of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace lox { namespace loggers {
9
10//==================================================================================================
11/// This is a very simple file logger for textual log outputs. The file name string provided
12/// in the constructor is not verified.
13/// The fileName may be changed by simply setting the public member #FileName.
14///
15/// In alignment with \alox principles (\alox does not throw!), the logger does not throw i/o
16/// exceptions. In debug-compilations, \alib warnings are issued.
17/// Recent system io/ errors are stored in public field# LastSystemError.
18/// The constructor tries to open/close the file with write permissions.
19/// For many applications, it should be enough to check this field after construction and
20/// take according actions on failure. Otherwise, errors may periodically be checked by an
21/// application (e.g., no space left on device, etc.).
22//==================================================================================================
24{
25 // #############################################################################################
26 // Internal fields
27 // #############################################################################################
28 protected:
29
30 /// Encapsulates the text file stream in a system dependent way.
32
33 /// Flag to prevent file open/close operations when multi line text logging is performed.
35
36
37 // #############################################################################################
38 // Public fields
39 // #############################################################################################
40 public:
41 /// The path and fileName to the log file.
43
44 /// Errors that usually indicate i/o problems. With construction of the logger,
45 /// the file is tried to be opened and closed, which might indicate major problems
46 /// (permissions, path, etc) with this public field very early.
47 SystemErrors LastSystemError = SystemErrors::None;
48
49
50 // #############################################################################################
51 // Constructor/destructor
52 // #############################################################################################
53 public:
54 //==========================================================================================
55 /// Creates a TextFileLogger.
56 /// @param fileName The filename (potentially including a path) of the output log file.
57 /// @param loggerName The name of the \e Logger. Defaults to "TEXTFILE".
58 //==========================================================================================
60 explicit TextFileLogger( const alib::String& fileName,
61 const alib::NString& loggerName =nullptr );
62
63 //==========================================================================================
64 /// Destructs a TextFileLogger
65 //==========================================================================================
66 virtual ~TextFileLogger() override {}
67
68 // #############################################################################################
69 // Protected methods
70 // #############################################################################################
71 protected:
72 //==========================================================================================
73 /// Opens the file.
74 //==========================================================================================
76 void openFile();
77
78 //==========================================================================================
79 /// Closes the file.
80 //==========================================================================================
82 void closeFile();
83
84 // #############################################################################################
85 // Abstract method implementations
86 // #############################################################################################
87 protected:
88 //==========================================================================================
89 /// Starts/ends log line. Appends a new-line character sequence to previously logged lines.
90 ///
91 /// @param phase Indicates the beginning or end of a log line.
92 /// @return Always returns true.
93 //==========================================================================================
95 virtual bool notifyLogOp( lang::Phase phase ) override;
96
97 //==========================================================================================
98 /// Writes the given region of the given string to the console.
99 ///
100 /// @param buffer The string to write a portion of.
101 /// @param start The start of the portion in \p{buffer} to write out.
102 /// @param length The length of the portion in \p{buffer} to write out.
103 /// @return The number of characters written, -1 on error.
104 //==========================================================================================
106 virtual integer logSubstring( const String& buffer,
107 integer start, integer length ) override;
108
109
110 //==========================================================================================
111 /// Empty implementation, not needed for this class
112 /// @param phase Indicates the beginning or end of a multi-line operation.
113 //==========================================================================================
115 virtual void notifyMultiLineOp ( lang::Phase phase ) override;
116
117}; // class TextFileLogger
118
119
120}} // namespace alib[::lox::loggers]
121
122/// Type alias in namespace \b alib.
124
125} // namespace [alib]
126
127
virtual ALIB_DLL void notifyMultiLineOp(lang::Phase phase) override
virtual ALIB_DLL bool notifyLogOp(lang::Phase phase) override
ALIB_DLL void openFile()
Opens the file.
virtual ~TextFileLogger() override
Destructs a TextFileLogger.
bool currentlyInMultiLineOp
Flag to prevent file open/close operations when multi line text logging is performed.
ALIB_DLL void closeFile()
Closes the file.
virtual ALIB_DLL integer logSubstring(const String &buffer, integer start, integer length) override
StringWriter writer
Encapsulates the text file stream in a system dependent way.
ALIB_DLL TextFileLogger(const alib::String &fileName, const alib::NString &loggerName=nullptr)
alib::AString FileName
The path and fileName to the log file.
#define ALIB_DLL
Definition alib.inl:496
#define ALIB_EXPORT
Definition alib.inl:488
Phase
Denotes a phase, e.g.,of a transaction.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
lox::loggers::TextFileLogger TextFileLogger
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2390
strings::compatibility::std::StringWriter StringWriter
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
system::SystemErrors SystemErrors
Type alias in namespace alib.