libDwm-0.9.45
Dwm::FileRoller Class Reference

This class can be used to roll over files such as log files. More...

#include <DwmFileRoller.hh>

Public Types

enum  CompressionEnum { e_compressionNone , e_compressionGzip , e_compressionBzip2 }
 Available compression types.
 

Public Member Functions

 FileRoller (const std::string &dir, const std::string &prefix, size_t maxSize, size_t numFiles, CompressionEnum compression=e_compressionNone)
 Constructor.
 
bool FilesNeedRolling () const
 Returns true if the active file (identified by the dir and prefix in the call to our constructor) is larger than our maximum file size (set with maxSize in our constructor).
 
bool FilesNeedRolling (int fd) const
 Returns true if the current write position of fd is larger than our maximum file size (set with maxSize in our constructor).
 
bool FilesNeedRolling (std::ostream &os) const
 Returns true if the current write position of os is larger than our maximum file size (set with maxSize in our constructor).
 
bool FilesNeedRolling (FILE *f) const
 Returns true if the current write position of f is larger than our maximum file size (set with maxSize in our constructor).
 
bool RollFiles ()
 Rolls the files.
 
size_t MaxSize () const
 Returns the max file size.
 
size_t MaxSize (size_t maxSize)
 Sets and returns the max file size.
 
size_t NumFiles () const
 Returns the max file size.
 
size_t NumFiles (size_t numFiles)
 Sets and returns the max file size.
 

Detailed Description

This class can be used to roll over files such as log files.

Typically an application logging to a file will periodically call one of the FilesNeedRolling() members, and if it returns true, close the logging file and then call RollFiles().

Constructor & Destructor Documentation

◆ FileRoller()

Dwm::FileRoller::FileRoller ( const std::string & dir,
const std::string & prefix,
size_t maxSize,
size_t numFiles,
CompressionEnum compression = e_compressionNone )

Constructor.

dir is the directory in which the files are stored. prefix is the name of the first file, which presumably your application is using for logging or the like. maxSize is the file size (in bytes) at which we'd like to roll over files. numFiles is the number of files we'd like to keep beyond the first file. compression may be set to use gzip or bzip2 compression.

Member Function Documentation

◆ FilesNeedRolling() [1/3]

bool Dwm::FileRoller::FilesNeedRolling ( FILE * f) const

Returns true if the current write position of f is larger than our maximum file size (set with maxSize in our constructor).

Here we assume that f is a FILE pointer being used to write to the active file (identified by the dir and prefix in the call to our constructor).

Note
This is a convenience routine that avoids the overhead of calling stat().

◆ FilesNeedRolling() [2/3]

bool Dwm::FileRoller::FilesNeedRolling ( int fd) const

Returns true if the current write position of fd is larger than our maximum file size (set with maxSize in our constructor).

Here we assume that fd is a descriptor being used to write to the active file (identified by the dir and prefix in the call to our constructor).

Note
This is a convenience routine that avoids the overhead of calling stat().

◆ FilesNeedRolling() [3/3]

bool Dwm::FileRoller::FilesNeedRolling ( std::ostream & os) const

Returns true if the current write position of os is larger than our maximum file size (set with maxSize in our constructor).

Here we assume that os is an ostream being used to write to the active file (identified by the dir and prefix in the call to our constructor).

Note
This is a convenience routine that avoids the overhead of calling stat().

◆ RollFiles()

bool Dwm::FileRoller::RollFiles ( )

Rolls the files.

The active file should be closed before calling this function.


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