# log4cpp::FileAppender Class Reference

`#include <FileAppender.hh>`

Inheritance diagram for log4cpp::FileAppender:

[legend]
Collaboration diagram for log4cpp::FileAppender:

[legend]
List of all members.

## Public Member Functions

| FileAppender (const std::string &name, const std::string &fileName, bool append=true, mode_t mode=00644)
| Constructs a FileAppender.
| FileAppender (const std::string &name, int fd)
| Constructs a FileAppender to an already open file descriptor.
virtual | ~FileAppender ()
virtual bool | reopen ()
| Reopens the logfile.
virtual void | close ()
| Closes the logfile.
virtual void | setAppend (bool append)
| Sets the append vs truncate flag.
virtual bool | getAppend () const
| Gets the value of the 'append' option.
virtual void | setMode (mode_t mode)
| Sets the file open mode.
virtual mode_t | getMode () const
| Gets the file open mode.

## Protected Member Functions

virtual void | _append (const LoggingEvent &event)
| Log in Appender specific way.

## Protected Attributes

const std::string | _fileName
int | _fd
int | _flags
mode_t | _mode

## Constructor & Destructor Documentation

log4cpp::FileAppender::FileAppender | ( | const std::string & | name,
|  | const std::string & | fileName,
|  | bool | append = `true`,
|  | mode_t | mode = `00644` |
| ) |  |  |

Constructs a FileAppender.

Parameters:

  | name | the name of the Appender.
  | fileName | the name of the file to which the Appender has to log.
  | append | whether the Appender has to truncate the file or just append to it if it already exists. Defaults to 'true'.
  | mode | file mode to open the logfile with. Defaults to 00644.

log4cpp::FileAppender::FileAppender | ( | const std::string & | name,
|  | int | fd |
| ) |  |  |

Constructs a FileAppender to an already open file descriptor.

Parameters:

  | name | the name of the Appender.
  | fd | the file descriptor to which the Appender has to log.

log4cpp::FileAppender::~FileAppender | ( |  | ) | `[virtual]`

## Member Function Documentation

bool log4cpp::FileAppender::reopen | ( |  | ) | `[virtual]`

Reopens the logfile.

This can be useful for logfiles that are rotated externally, e.g. by logrotate. This method is a NOOP for FileAppenders that have been constructed with a file descriptor.

Returns:
  true if the reopen succeeded.

Reimplemented from log4cpp::AppenderSkeleton.

void log4cpp::FileAppender::close | ( |  | ) | `[virtual]`

Closes the logfile.

Implements log4cpp::AppenderSkeleton.

void log4cpp::FileAppender::setAppend | ( | bool | append | ) | `[virtual]`

Sets the append vs truncate flag.

NB. currently the FileAppender opens the logfile in the constructor. Therefore this method is too late to influence the first file opening. We'll need something similar to log4j's activateOptions().

Parameters:

  | append | false to truncate, true to append

bool log4cpp::FileAppender::getAppend | ( |  | ) | const`[virtual]`

Gets the value of the 'append' option.

void log4cpp::FileAppender::setMode | ( | mode_t | mode | ) | `[virtual]`

Sets the file open mode.

mode_t log4cpp::FileAppender::getMode | ( |  | ) | const`[virtual]`

Gets the file open mode.

void log4cpp::FileAppender::_append | ( | const LoggingEvent & | event | ) | `[protected, virtual]`

Log in Appender specific way.

Subclasses of Appender should implement this method to perform actual logging.

Parameters:

  | event | The LoggingEvent to log.

Implements log4cpp::AppenderSkeleton.

Reimplemented in log4cpp::RollingFileAppender.

## Member Data Documentation

const std::string log4cpp::FileAppender::_fileName`[protected]`

int log4cpp::FileAppender::_fd`[protected]`

int log4cpp::FileAppender::_flags`[protected]`

mode_t log4cpp::FileAppender::_mode`[protected]`

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

- FileAppender.hh
- FileAppender.cpp