|
PTLib
Version 2.18.8
|
Information on how to rotate files. More...
#include <file.h>

Public Member Functions | |
| RotateInfo (const PDirectory &dir=PDirectory(), const PString &prefix=PString::Empty(), const PString &suffix=PString::Empty(), const PString ×tamp=DefaultTimestamp(), off_t maxSize=1000000000, off_t minFree=-10) | |
| RotateInfo (const RotateInfo &other) | |
| RotateInfo & | operator= (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 PString & | DefaultTimestamp () |
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 |
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.
|
explicit |
| PFile::RotateInfo::RotateInfo | ( | const RotateInfo & | other | ) |
|
inlinevirtual |
| bool PFile::RotateInfo::CanRotate | ( | ) | const |
Inidcate that the RotateInfo is configured so that rotations can be made via the Rotate() function.
|
static |
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.
| file | File to be rotated. |
| rotatedTo | Name to which file will be rotated |
|
virtual |
Callback when have a message on thte rotation.
| error | Message is about an error, otherwise just informative. |
| msg | Message to output |
|
virtual |
Callback to open the file.
The default behaviour calls file.Open(PFile::WriteOnly).
| file | File 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.
| force | Force rotate regardless of time/size conditions |
| 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.