Poco

class SimpleFileChannel

Library: Foundation
Package: Logging
Header: Poco/SimpleFileChannel.h

Description

A Channel that writes to a file. This class only supports simple log file rotation.

For more features, see the FileChannel class.

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.

Log file rotation based on log file size is supported.

If rotation is enabled, the SimpleFileChannel will alternate between two log files. If the size of the primary log file exceeds a specified limit, the secondary log file will be used, and vice versa.

Log rotation is configured with the "rotation" property, which supports the following values:

The path of the (primary) log file can be specified with the "path" property. Optionally, the path of the secondary log file can be specified with the "secondaryPath" property.

If no secondary path is specified, the secondary path will default to <primaryPath>.1.

Inheritance

Direct Base Classes: Channel

All Base Classes: Channel, Configurable, RefCountedObject

Member Summary

Member Functions: close, creationDate, getProperty, log, open, path, rotate, secondaryPath, setProperty, setRotation, size

Inherited Functions: close, duplicate, getProperty, log, open, referenceCount, release, setProperty

Constructors

SimpleFileChannel

SimpleFileChannel();

Creates the FileChannel.

SimpleFileChannel

SimpleFileChannel(
    const std::string & path
);

Creates the FileChannel for a file with the given path.

Destructor

~SimpleFileChannel protected virtual

~SimpleFileChannel();

Member Functions

close virtual

void close();

Closes the FileChannel.

See also: Poco::Channel::close()

creationDate

Timestamp creationDate() const;

Returns the log file's creation date.

getProperty virtual

std::string getProperty(
    const std::string & name
) const;

Returns the value of the property with the given name. See setProperty() for a description of the supported properties.

See also: Poco::Channel::getProperty()

log virtual

void log(
    const Message & msg
);

Logs the given message to the file.

See also: Poco::Channel::log()

open virtual

void open();

Opens the FileChannel and creates the log file if necessary.

See also: Poco::Channel::open()

path

const std::string & path() const;

Returns the log file's primary path.

secondaryPath

const std::string & secondaryPath() const;

Returns the log file's secondary path.

setProperty virtual

void setProperty(
    const std::string & name,
    const std::string & value
);

Sets the property with the given name.

The following properties are supported:

See also: Poco::Channel::setProperty()

size

UInt64 size() const;

Returns the log file's current size in bytes.

rotate protected

void rotate();

setRotation protected

void setRotation(
    const std::string & rotation
);

Variables

PROP_PATH static

static const std::string PROP_PATH;

PROP_ROTATION static

static const std::string PROP_ROTATION;

PROP_SECONDARYPATH static

static const std::string PROP_SECONDARYPATH;