PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PFile::RotateInfo Struct Reference

Information on how to rotate files. More...

#include <file.h>

Collaboration diagram for PFile::RotateInfo:

Public Member Functions

 RotateInfo (const PDirectory &dir=PDirectory(), const PString &prefix=PString::Empty(), const PString &suffix=PString::Empty(), const PString &timestamp=DefaultTimestamp(), off_t maxSize=1000000000, off_t minFree=-10)
 
 RotateInfo (const RotateInfo &other)
 
RotateInfooperator= (const RotateInfo &other)
 
virtual ~RotateInfo ()
 
bool CanRotate () const
 Inidcate that the RotateInfo is configured so that rotations can be made via the Rotate() function. More...
 
bool Rotate (PFile &activeFile, bool force=false, const PTime &now=PTime())
 Execute a rotation. More...
 
virtual void OnCloseFile (PFile &file, const PFilePath &rotatedTo)
 Callback when a rotation of an open file is about to be performed. More...
 
virtual bool OnOpenFile (PFile &file)
 Callback to open the file. More...
 
virtual void OnMessage (bool error, const PString &msg)
 Callback when have a message on thte rotation. More...
 
 P_DECLARE_STREAMABLE_ENUM (Period, SizeOnly, Hourly, Daily, Weekly, Monthly)
 

Static Public Member Functions

static const PStringDefaultTimestamp ()
 

Public Attributes

PDirectory m_directory
 Destination directory for rotated file, default to same s log file. More...
 
PFilePathString m_prefix
 File name prefix, default PProcess::GetName() More...
 
PString m_timestamp
 Time template for rotated file, default "_yyyy_MM_dd_hh_mm". More...
 
int m_timeZone
 TIme zone for output and rotated file names. More...
 
PFilePathString m_suffix
 File name suffix, default ".log". More...
 
off_t m_maxSize
 Size in bytes which triggers a rotation, default zero disables. More...
 
off_t m_freeDisk
 Minimum free space for the disk. Negative is percentage, positive is bytes. More...
 
Period m_period
 Rotate on the peroid regardless of size. More...
 
unsigned m_maxFileCount
 When this many files have been rotated, oldest is deleted. More...
 
PTimeInterval m_maxFileAge
 Rotated files older than this are deleted. More...
 
PTime m_lastTime
 

Detailed Description

Information on how to rotate files.

The system will generate a new file path via m_directory + m_prefix + PTime::AsString(m_timeTemplate) + m_suffix which is used with renaming/moving the file.

The wildcard: m_directory + m_prefix + '*' + m_suffix is used to determine the files to remove.

Constructor & Destructor Documentation

PFile::RotateInfo::RotateInfo ( const PDirectory dir = PDirectory(),
const PString prefix = PString::Empty(),
const PString suffix = PString::Empty(),
const PString timestamp = DefaultTimestamp(),
off_t  maxSize = 1000000000,
off_t  minFree = -10 
)
explicit
PFile::RotateInfo::RotateInfo ( const RotateInfo other)
virtual PFile::RotateInfo::~RotateInfo ( )
inlinevirtual

Member Function Documentation

bool PFile::RotateInfo::CanRotate ( ) const

Inidcate that the RotateInfo is configured so that rotations can be made via the Rotate() function.

static const PString& PFile::RotateInfo::DefaultTimestamp ( )
static
virtual void PFile::RotateInfo::OnCloseFile ( PFile file,
const PFilePath rotatedTo 
)
virtual

Callback when a rotation of an open file is about to be performed.

This is called just before the PFile is closed, and new one is opened.

Parameters
fileFile to be rotated.
rotatedToName to which file will be rotated
virtual void PFile::RotateInfo::OnMessage ( bool  error,
const PString msg 
)
virtual

Callback when have a message on thte rotation.

Parameters
errorMessage is about an error, otherwise just informative.
msgMessage to output
virtual bool PFile::RotateInfo::OnOpenFile ( PFile file)
virtual

Callback to open the file.

The default behaviour calls file.Open(PFile::WriteOnly).

Parameters
fileFile to be reopened.
RotateInfo& PFile::RotateInfo::operator= ( const RotateInfo other)
PFile::RotateInfo::P_DECLARE_STREAMABLE_ENUM ( Period  ,
SizeOnly  ,
Hourly  ,
Daily  ,
Weekly  ,
Monthly   
)
bool PFile::RotateInfo::Rotate ( PFile activeFile,
bool  force = false,
const PTime now = PTime() 
)

Execute a rotation.

The file is closed, renamed to new name, and re-opened. The old rotated files are are aos checked and deleted according to the criteria here.

If force is false then the file must be larger than m_maxSize. If force is true the the file is moved and re-opened regardless of it's current size.

Note, m_maxSize must be non zero and m_timestamp must be non-empty string for this to operate, even in the force == true case.

Parameters
forceForce rotate regardless of time/size conditions

Member Data Documentation

PDirectory PFile::RotateInfo::m_directory

Destination directory for rotated file, default to same s log file.

off_t PFile::RotateInfo::m_freeDisk

Minimum free space for the disk. Negative is percentage, positive is bytes.

PTime PFile::RotateInfo::m_lastTime
PTimeInterval PFile::RotateInfo::m_maxFileAge

Rotated files older than this are deleted.

unsigned PFile::RotateInfo::m_maxFileCount

When this many files have been rotated, oldest is deleted.

off_t PFile::RotateInfo::m_maxSize

Size in bytes which triggers a rotation, default zero disables.

Period PFile::RotateInfo::m_period

Rotate on the peroid regardless of size.

PFilePathString PFile::RotateInfo::m_prefix

File name prefix, default PProcess::GetName()

PFilePathString PFile::RotateInfo::m_suffix

File name suffix, default ".log".

PString PFile::RotateInfo::m_timestamp

Time template for rotated file, default "_yyyy_MM_dd_hh_mm".

int PFile::RotateInfo::m_timeZone

TIme zone for output and rotated file names.


The documentation for this struct was generated from the following file: