CppLogging 1.0.5.0
C++ Logging Library
Loading...
Searching...
No Matches
file_appender.h
Go to the documentation of this file.
1
9#ifndef CPPLOGGING_APPENDERS_FILE_APPENDER_H
10#define CPPLOGGING_APPENDERS_FILE_APPENDER_H
11
12#include "logging/appender.h"
13
14#include "filesystem/filesystem.h"
15
16#include <atomic>
17
18namespace CppLogging {
19
21
29class FileAppender : public Appender
30{
31public:
33
39 explicit FileAppender(const CppCommon::Path& file, bool truncate = false, bool auto_flush = false, bool auto_start = true);
40 FileAppender(const FileAppender&) = delete;
42 virtual ~FileAppender();
43
46
47 // Implementation of Appender
48 bool IsStarted() const noexcept override { return _started; }
49 bool Start() override;
50 bool Stop() override;
51 void AppendRecord(Record& record) override;
52 void Flush() override;
53
54private:
55 std::atomic<bool> _started{false};
56 CppCommon::Timestamp _retry{0};
57 CppCommon::File _file;
58 bool _truncate;
59 bool _auto_flush;
60
62 /*
63 - If the file is opened and ready to write immediately returns true
64 - If the last retry was earlier than 100ms immediately returns false
65 - If the file is closed try to open it for writing, returns true/false
66
67 \return 'true' if the file was successfully prepared, 'false' if the file failed to be prepared
68 */
69 bool PrepareFile();
71 /*
72 \return 'true' if the file was successfully closed, 'false' if the file failed to close
73 */
74 bool CloseFile();
75};
76
77} // namespace CppLogging
78
81#endif // CPPLOGGING_APPENDERS_FILE_APPENDER_H
Logging appender interface definition.
Logging appender interface.
Definition appender.h:33
bool IsStarted() const noexcept override
Is the logging element started?
FileAppender & operator=(FileAppender &&)=delete
bool Start() override
Start the logging element.
FileAppender & operator=(const FileAppender &)=delete
FileAppender(FileAppender &&)=delete
FileAppender(const FileAppender &)=delete
void AppendRecord(Record &record) override
Append the given logging record.
void Flush() override
Flush the logging appender.
bool Stop() override
Stop the logging element.
Logging record.
Definition record.h:37
C++ Logging project definitions.
Definition appender.h:15