CppLogging  1.0.4.0
C++ Logging Library
rolling_file_appender.h
Go to the documentation of this file.
1 
9 #ifndef CPPLOGGING_APPENDERS_ROLLING_FILE_APPENDER_H
10 #define CPPLOGGING_APPENDERS_ROLLING_FILE_APPENDER_H
11 
12 #include "logging/appender.h"
13 
14 #include "filesystem/filesystem.h"
15 
16 #include <memory>
17 
18 namespace CppLogging {
19 
22 {
23  YEAR,
24  MONTH,
25  DAY,
26  HOUR,
27  MINUTE,
28  SECOND
29 };
30 
32 
37 template <class TOutputStream>
38 TOutputStream& operator<<(TOutputStream& stream, TimeRollingPolicy policy);
39 
41 
60 {
61  friend class SizePolicyImpl;
62  friend class TimePolicyImpl;
63 
64 public:
66 
88  explicit RollingFileAppender(const CppCommon::Path& path, TimeRollingPolicy policy = TimeRollingPolicy::DAY, const std::string& pattern = "{UtcDateTime}.log", bool archive = false, bool truncate = false, bool auto_flush = false, bool auto_start = true);
90 
110  explicit RollingFileAppender(const CppCommon::Path& path, const std::string& filename, const std::string& extension, size_t size = 104857600, size_t backups = 10, bool archive = false, bool truncate = false, bool auto_flush = false, bool auto_start = true);
113  virtual ~RollingFileAppender();
114 
117 
118  // Implementation of Appender
119  bool IsStarted() const noexcept override;
120  bool Start() override;
121  bool Stop() override;
122  void AppendRecord(Record& record) override;
123  void Flush() override;
124 
125 protected:
127 
130  virtual void onArchiveThreadInitialize() {}
132 
135  virtual void onArchiveThreadCleanup() {}
136 
137 private:
138  class Impl;
139 
140  Impl& impl() noexcept { return reinterpret_cast<Impl&>(_storage); }
141  const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }
142 
143  static const size_t StorageSize = 608;
144  static const size_t StorageAlign = 8;
145  alignas(StorageAlign) std::byte _storage[StorageSize];
146 };
147 
148 } // namespace CppLogging
149 
150 #include "rolling_file_appender.inl"
151 
152 #endif // CPPLOGGING_APPENDERS_ROLLING_FILE_APPENDER_H
Logging appender interface definition.
Logging appender interface.
Definition: appender.h:33
Logging record.
Definition: record.h:37
virtual void onArchiveThreadInitialize()
Initialize archivation thread handler.
void AppendRecord(Record &record) override
Append the given logging record.
bool IsStarted() const noexcept override
Is the logging element started?
bool Start() override
Start the logging element.
RollingFileAppender & operator=(RollingFileAppender &&appender)=delete
bool Stop() override
Stop the logging element.
RollingFileAppender(const RollingFileAppender &)=delete
void Flush() override
Flush the logging appender.
RollingFileAppender & operator=(const RollingFileAppender &)=delete
RollingFileAppender(const CppCommon::Path &path, TimeRollingPolicy policy=TimeRollingPolicy::DAY, const std::string &pattern="{UtcDateTime}.log", bool archive=false, bool truncate=false, bool auto_flush=false, bool auto_start=true)
Initialize the rolling file appender with a time-based policy.
virtual void onArchiveThreadCleanup()
Cleanup archivation thread handler.
RollingFileAppender(RollingFileAppender &&appender)=delete
C++ Logging project definitions.
Definition: appender.h:15
TimeRollingPolicy
Time rolling policy.
@ SECOND
Second rolling policy.
@ MONTH
Monthly rolling policy.
@ MINUTE
Minute rolling policy.
@ DAY
Daily rolling policy.
@ YEAR
Year rolling policy.
@ HOUR
Hour rolling policy.
TOutputStream & operator<<(TOutputStream &stream, TimeRollingPolicy policy)
Stream output: Time rolling policy.
Rolling file appender inline implementation.