CppLogging  1.0.4.0
C++ Logging Library
Public Member Functions | Protected Member Functions | Friends | List of all members
CppLogging::RollingFileAppender Class Reference

Rolling file appender. More...

#include <rolling_file_appender.h>

Inheritance diagram for CppLogging::RollingFileAppender:
CppLogging::Appender CppLogging::Element

Public Member Functions

 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. More...
 
 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)
 Initialize the rolling file appender with a size-based policy. More...
 
 RollingFileAppender (const RollingFileAppender &)=delete
 
 RollingFileAppender (RollingFileAppender &&appender)=delete
 
virtual ~RollingFileAppender ()
 
RollingFileAppenderoperator= (const RollingFileAppender &)=delete
 
RollingFileAppenderoperator= (RollingFileAppender &&appender)=delete
 
bool IsStarted () const noexcept override
 Is the logging element started? More...
 
bool Start () override
 Start the logging element. More...
 
bool Stop () override
 Stop the logging element. More...
 
void AppendRecord (Record &record) override
 Append the given logging record. More...
 
void Flush () override
 Flush the logging appender. More...
 

Protected Member Functions

virtual void onArchiveThreadInitialize ()
 Initialize archivation thread handler. More...
 
virtual void onArchiveThreadCleanup ()
 Cleanup archivation thread handler. More...
 

Friends

class SizePolicyImpl
 
class TimePolicyImpl
 

Detailed Description

Rolling file appender.

Rolling file appender writes the given logging record into the file and performs file rolling operation depends on the given policy. In case of any IO error this appender will lost the logging record, but try to recover from fail in a short interval of 100ms.

Time-based rolling policy will create a new logging file to write into using a special pattern (contains date & time placeholders).

Size-based rolling policy will create a new logging file to write when the current file size exceeded size limit. Logging backups are indexed and its count could be limited as well.

It is possible to enable archivation of the logging backups in a background thread.

Not thread-safe.

Definition at line 59 of file rolling_file_appender.h.

Constructor & Destructor Documentation

◆ RollingFileAppender() [1/4]

CppLogging::RollingFileAppender::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 
)
explicit

Initialize the rolling file appender with a time-based policy.

Time-based policy composes logging filename from the given pattern using the following placeholders:

  • {UtcDateTime} / {LocalDateTime} - converted to the UTC/local date & time (e.g. "1997-07-16T192030Z" / "1997-07-16T192030+0100")
  • {UtcDate} / {LocalDate} - converted to the UTC/local date (e.g. "1997-07-16")
  • {UtcTime} / {LocalTime} - converted to the UTC/local time (e.g. "192030Z" / "192030+0100")
  • {UtcYear} / {LocalYear} - converted to the UTC/local four-digits year (e.g. "1997")
  • {UtcMonth} / {LocalMonth} - converted to the UTC/local two-digits month (e.g. "07")
  • {UtcDay} / {LocalDay} - converted to the UTC/local two-digits day (e.g. "16")
  • {UtcHour} / {LocalHour} - converted to the UTC/local two-digits hour (e.g. "19")
  • {UtcMinute} / {LocalMinute} - converted to the UTC/local two-digits minute (e.g. "20")
  • {UtcSecond} / {LocalSecond} - converted to the UTC/local two-digits second (e.g. "30")
  • {UtcTimezone} / {LocalTimezone} - converted to the UTC/local timezone suffix (e.g. "Z" / "+0100")
Parameters
path- Logging path
policy- Time-based rolling policy (default is TimeRollingPolicy::DAY)
pattern- Logging pattern (default is "{UtcDateTime}.log")
archive- Archivation flag (default is false)
truncate- Truncate flag (default is false)
auto_flush- Auto-flush flag (default is false)
auto_start- Auto-start flag (default is true)

Definition at line 1176 of file rolling_file_appender.cpp.

◆ RollingFileAppender() [2/4]

CppLogging::RollingFileAppender::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 
)
explicit

Initialize the rolling file appender with a size-based policy.

Size-based policy for 5 backups works in a following way:

example.log -> example.1.log example.1.log -> example.2.log example.2.log -> example.3.log example.3.log -> example.4.log example.4.log -> example.5.log example.5.log -> remove

Parameters
path- Logging path
filename- Logging filename
extension- Logging extension
size- Rolling size limit in bytes (default is 100 megabytes)
backups- Rolling backups count (default is 10)
archive- Archivation flag (default is false)
truncate- Truncate flag (default is false)
auto_flush- Auto-flush flag (default is false)
auto_start- Auto-start flag (default is true)

Definition at line 1187 of file rolling_file_appender.cpp.

◆ RollingFileAppender() [3/4]

CppLogging::RollingFileAppender::RollingFileAppender ( const RollingFileAppender )
delete

◆ RollingFileAppender() [4/4]

CppLogging::RollingFileAppender::RollingFileAppender ( RollingFileAppender &&  appender)
delete

◆ ~RollingFileAppender()

CppLogging::RollingFileAppender::~RollingFileAppender ( )
virtual

Definition at line 1198 of file rolling_file_appender.cpp.

Member Function Documentation

◆ AppendRecord()

void CppLogging::RollingFileAppender::AppendRecord ( Record record)
overridevirtual

Append the given logging record.

Parameters
record- Logging record

Implements CppLogging::Appender.

Definition at line 1207 of file rolling_file_appender.cpp.

◆ Flush()

void CppLogging::RollingFileAppender::Flush ( )
overridevirtual

Flush the logging appender.

Reimplemented from CppLogging::Appender.

Definition at line 1208 of file rolling_file_appender.cpp.

◆ IsStarted()

bool CppLogging::RollingFileAppender::IsStarted ( ) const
overridevirtualnoexcept

Is the logging element started?

Reimplemented from CppLogging::Element.

Definition at line 1204 of file rolling_file_appender.cpp.

◆ onArchiveThreadCleanup()

virtual void CppLogging::RollingFileAppender::onArchiveThreadCleanup ( )
inlineprotectedvirtual

Cleanup archivation thread handler.

This handler can be used to cleanup priority or affinity of the archivation thread.

Definition at line 135 of file rolling_file_appender.h.

◆ onArchiveThreadInitialize()

virtual void CppLogging::RollingFileAppender::onArchiveThreadInitialize ( )
inlineprotectedvirtual

Initialize archivation thread handler.

This handler can be used to initialize priority or affinity of the archivation thread.

Definition at line 130 of file rolling_file_appender.h.

◆ operator=() [1/2]

RollingFileAppender& CppLogging::RollingFileAppender::operator= ( const RollingFileAppender )
delete

◆ operator=() [2/2]

RollingFileAppender& CppLogging::RollingFileAppender::operator= ( RollingFileAppender &&  appender)
delete

◆ Start()

bool CppLogging::RollingFileAppender::Start ( )
overridevirtual

Start the logging element.

Returns
'true' if the logging element was successfully started, 'false' if the logging element failed to start

Reimplemented from CppLogging::Element.

Definition at line 1205 of file rolling_file_appender.cpp.

◆ Stop()

bool CppLogging::RollingFileAppender::Stop ( )
overridevirtual

Stop the logging element.

Returns
'true' if the logging element was successfully stopped, 'false' if the logging element failed to stop

Reimplemented from CppLogging::Element.

Definition at line 1206 of file rolling_file_appender.cpp.

Friends And Related Function Documentation

◆ SizePolicyImpl

friend class SizePolicyImpl
friend

Definition at line 61 of file rolling_file_appender.h.

◆ TimePolicyImpl

friend class TimePolicyImpl
friend

Definition at line 62 of file rolling_file_appender.h.


The documentation for this class was generated from the following files: