Logo Search packages:      
Sourcecode: poco version File versions  Download package

Poco::FileChannel Class Reference

#include <FileChannel.h>

Inheritance diagram for Poco::FileChannel:

Poco::Channel Poco::Configurable Poco::RefCountedObject

List of all members.


Detailed Description

A Channel that writes to a file. This class supports flexible log file rotation and archiving, as well as automatic purging of archived log files.

Only the message's text is written, followed by a newline.

Chain this channel to a FormattingChannel with an appropriate Formatter to control what is in the text.

The FileChannel support log file rotation based on log file size or time intervals. Archived log files can be compressed in gzip format. Older archived files can be automatically deleted (purged).

The rotation strategy can be specified with the "rotation" property, which can take one of the follwing values:

never: no log rotation [day,][hh]:mm: the file is rotated on specified day/time day - day is specified as long or short day name (Monday|Mon, Tuesday|Tue, ... ); day can be omitted, in which case log is rotated every day hh - valid hour range is 00-23; hour can be omitted, in which case log is rotated every hour mm - valid minute range is 00-59; minute must be specified daily: the file is rotated daily weekly: the file is rotated every seven days monthly: the file is rotated every 30 days <n> hours: the file is rotated every <n> hours, where <n> is an integer greater than zero. <n> days: the file is rotated every <n> days, where <n> is an integer greater than zero. <n> weeks: the file is rotated every <n> weeks, where <n> is an integer greater than zero. <n> months: the file is rotated every <n> months, where <n> is an integer greater than zero and a month has 30 days. <n>: the file is rotated when its size exceeds <n> bytes. <n> K: the file is rotated when its size exceeds <n> Kilobytes. <n> M: the file is rotated when its size exceeds <n> Megabytes.

Using the "archive" property it is possible to specify how archived log files are named. The following values for the "archive" property are supported:

number: A number, starting with 0, is appended to the name of archived log files. The newest archived log file always has the number 0. For example, if the log file is named "access.log", and it fulfils the criteria for rotation, the file is renamed to "access.log.0". If a file named "access.log.0" already exists, it is renamed to "access.log.1", and so on. timestamp: A timestamp is appended to the log file name. For example, if the log file is named "access.log", and it fulfils the criteria for rotation, the file is renamed to "access.log.20050802110300".

Using the "times" property it is possible to specify time mode for the day/time based rotation. The following values for the "times" property are supported:

utc: Rotation strategy is based on UTC time (default). local: Rotation strategy is based on local time.

Archived log files can be compressed using the gzip compression method. Compressing can be controlled with the "compression" property. The following values for the "compress" property are supported:

true: Compress archived log files. false: Do not compress archived log files.

Archived log files can be automatically purged, either if they reach a certain age, or if the number of archived log files reaches a given maximum number. This is controlled by the purgeAge and purgeCount properties.

The purgeAge property can have the following values:

<n> [seconds] the maximum age is <n> seconds. <n> minutes: the maximum age is <n> minutes. <n> hours: the maximum age is <n> hours. <n> days: the maximum age is <n> days. <n> weeks: the maximum age is <n> weeks. <n> months: the maximum age is <n> months, where a month has 30 days.

The purgeCount property has an integer value that specifies the maximum number of archived log files. If the number is exceeded, archived log files are deleted, starting with the oldest.

For a more lightweight file channel class, see SimpleFileChannel.

Definition at line 58 of file FileChannel.h.


Public Member Functions

void close ()
 Opens the FileChannel and creates the log file if necessary.
Timestamp creationDate () const
void duplicate () const
 FileChannel (const std::string &path)
 Creates the FileChannel.
std::string getProperty (const std::string &name) const
void log (const Message &msg)
 Closes the FileChannel.
void open ()
 Creates the FileChannel for a file with the given path.
const std::string & path () const
 Returns the log file's current size in bytes.
int referenceCount () const
void release () const
 Increments the object's reference count.
void setProperty (const std::string &name, const std::string &value)
 Logs the given message to the file.
UInt64 size () const
 Returns the log file's creation date.

Static Public Attributes

static const std::string PROP_ARCHIVE = "archive"
static const std::string PROP_COMPRESS = "compress"
static const std::string PROP_PATH = "path"
 Returns the log file's path.
static const std::string PROP_PURGEAGE = "purgeAge"
static const std::string PROP_PURGECOUNT = "purgeCount"
static const std::string PROP_ROTATION = "rotation"
static const std::string PROP_TIMES = "times"

Protected Member Functions

void purge ()
void setArchive (const std::string &archive)
void setCompress (const std::string &compress)
void setPurgeAge (const std::string &age)
void setPurgeCount (const std::string &count)
void setRotation (const std::string &rotation)

Private Attributes

std::string _archive
bool _compress
FastMutex _mutex
ArchiveStrategy_pArchiveStrategy
std::string _path
LogFile_pFile
PurgeStrategy_pPurgeStrategy
RotateStrategy_pRotateStrategy
std::string _purgeAge
std::string _purgeCount
std::string _rotation
std::string _times

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

Generated by  Doxygen 1.6.0   Back to index