ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
textfilelogger.cpp
1using namespace alib;
2
4 const alib::NString& loggerName )
5: PlainTextLogger( loggerName, "TEXTFILE" )
6, ma( ALIB_DBG("TextFileLogger",) 8 ) {
7 FileName << fileName;
8
9 // test open file for test
10 ALIB_STRINGS_TO_NARROW(FileName,nFileName,1024)
11 auto* os= new std::ofstream( nFileName, std::ios::app );
12 if ( !os->is_open() ) {
13 LastSystemError= std::errc(errno);
14 ALIB_WARNING( "ALOX", "Could not open file: \"{}\". System error code: {}",
16 }
17 else
18 // test run OK
19 os->close();
20
21 delete os;
22}
23
25 ALIB_STRINGS_TO_NARROW(FileName,nFileName,1024)
26 ofs= new std::ofstream( nFileName, std::ios::app );
27 if ( !ofs->is_open() ) {
28 LastSystemError= std::errc(errno);
29 ALIB_WARNING( "ALOX", "Could not open file: \"{}\". System error code: {}",
31 delete ofs; ofs= nullptr;
32 return;
33 }
34
35 LastSystemError= std::errc(0);
36 writer.Construct( *ofs, ma );
37}
38
40 if( ofs == nullptr )
41 return;
42
43 writer.Destruct();
44 ofs->close();
45 delete ofs;
46}
47
48
50 // save state (to have it in logText)
52
53 // open/close the file
54 if ( phase == lang::Phase::Begin )
55 openFile();
56 else if( ofs != nullptr )
57 closeFile();
58}
59
61 if ( ofs != nullptr && phase == lang::Phase::End )
62 (*ofs) << std::endl;
63
64 // open/close
66 if ( phase == lang::Phase::Begin )
67 openFile();
68 else
69 closeFile();
70 }
71
72 return LastSystemError == std::errc(0);
73}
74
76 if (ofs == nullptr || LastSystemError != std::errc(0))
77 return 0;
78 integer printedWidth;
79 writer->Write( buffer.Substring<NC>( start, length ), &printedWidth );
80 return printedWidth;
81}
#define ALIB_WARNING(domain,...)
#define ALIB_DBG(...)
virtual void notifyMultiLineOp(lang::Phase phase) override
lang::Placeholder< OStreamWriter< nchar, MonoAllocator, true > > writer
virtual bool notifyPlainTextLogOp(lang::Phase phase) override
bool currentlyInMultiLineOp
Flag to prevent file open/close operations when multi-line text logging is performed.
std::ofstream * ofs
Encapsulates the text file stream in a system-dependent way.
MonoAllocator ma
Allocator used for the #"std::OStreamWriter".
virtual integer logPlainTextPart(const String &buffer, integer start, integer length) override
TextFileLogger(const alib::String &fileName, const alib::NString &loggerName=nullptr)
alib::AString FileName
The path and fileName to the log file.
PlainTextLogger(const NString &name, const NString &typeName)
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
Definition string.hpp:368
Phase
Denotes a phase, e.g.,of a transaction.
@ Begin
The start of a transaction.
@ End
The end of a transaction.
Definition alox.cpp:14
strings::TString< nchar > NString
Type alias in namespace #"%alib".
Definition string.hpp:2174
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp:149
strings::TString< character > String
Type alias in namespace #"%alib".
Definition string.hpp:2165
#define ALIB_STRINGS_TO_NARROW( src, dest, bufSize)