man Log::Log4perl::Appender::File () - Log to file

NAME

Log::Log4perl::Appender::File - Log to file

SYNOPSIS

    use Log::Log4perl::Appender::File;

    my $app = Log::Log4perl::Appender::File->new(
      filename  => 'file.log',
      mode      => 'append',
      autoflush => 1,
      umask     => 0222,
    );

    $file->log(message => "Log me\n");

DESCRIPTION

This is a simple appender for writing to a file.

The CWlog() method takes a single scalar. If a newline character should terminate the message, it has to be added explicitely.

Upon destruction of the object, the filehandle to access the file is flushed and closed.

If you want to switch over to a different logfile, use the CWfile_switch($newfile) method which will first close the old file handle and then open a one to the new file specified.

OPTIONS

filename
Name of the log file.
mode
Messages will be append to the file if CW$mode is set to the string CW"append". Will clobber the file if set to CW"clobber". If it is CW"pipe", the file will be understood as executable to pipe output to. Default mode is CW"append".
autoflush
CWautoflush, if set to a true value, triggers flushing the data out to the file on every call to CWlog(). CWautoflush is on by default.
umask
Specifies the CWumask to use when creating the file, determining the file's permission settings. If set to CW0222 (default), new files will be created with CWrw-r--r-- permissions. If set to CW0000, new files will be created with CWrw-rw-rw- permissions.
utf8
If you're printing out Unicode strings, the output filehandle needs to be set into CW:utf8 mode:
    my $app = Log::Log4perl::Appender::File->new(
      filename  => 'file.log',
      mode      => 'append',
      utf8      => 1,
    );
binmode
To manipulate the output filehandle via CWbinmode(), use the binmode parameter:
    my $app = Log::Log4perl::Appender::File->new(
      filename  => 'file.log',
      mode      => 'append',
      binmode   => ":utf8",
    );
A setting of :utf8 for CWbinmode is equivalent to specifying the CWutf8 option (see above).
recreate
Normally, if a file appender logs to a file and the file gets moved to a different location (e.g. via CWmv), the appender's open file handle will automatically follow the file to the new location. This may be undesirable. When using an external logfile rotator, for example, the appender should create a new file under the old name and start logging into it. If the CWrecreate option is set to a true value, CWLog::Log4perl::Appender::File will do exactly that. It defaults to false. Check the CWrecreate_check_interval option for performance optimizations with this feature.
recreate_check_interval
In CWrecreate mode, the appender has to continuously check if the file it is logging to is still in the same location. This check is fairly expensive, since it has to call CWstat on the file name and figure out if its inode has changed. Doing this with every call to CWlog can be prohibitively expensive. Setting it to a positive integer value N will only check the file every N seconds. It defaults to 30. This obviously means that the appender will continue writing to a moved file until the next check occurs, in the worst case this will happen CWrecreate_check_interval seconds after the file has been moved or deleted. If this is undesirable, setting CWrecreate_check_interval to 0 will have the appender appender check the file with every call to CWlog().

Design and implementation of this module has been greatly inspired by Dave Rolsky's CWLog::Dispatch appender framework.

AUTHOR

Mike Schilli <log4perl@perlmeister.com>, 2003, 2005