Log-Log4perl
view release on metacpan or search on metacpan
lib/Log/Log4perl/Appender/File.pm view on Meta::CPAN
__END__
=encoding utf8
=head1 NAME
Log::Log4perl::Appender::File - Log to file
=head1 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");
=head1 DESCRIPTION
This is a simple appender for writing to a file.
The C<log()> method takes a single scalar. If a newline character
should terminate the message, it has to be added explicitly.
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
C<file_switch($newfile)> method which will first close the old
file handle and then open a one to the new file specified.
=head2 OPTIONS
=over 4
=item filename
Name of the log file.
=item mode
Messages will be append to the file if C<$mode> is set to the
string C<"append">. Will clobber the file
if set to C<"clobber">. If it is C<"pipe">, the file will be understood
as executable to pipe output to. Default mode is C<"append">.
=item autoflush
C<autoflush>, if set to a true value, triggers flushing the data
out to the file on every call to C<log()>. C<autoflush> is on by default.
=item syswrite
C<syswrite>, if set to a true value, makes sure that the appender uses
syswrite() instead of print() to log the message. C<syswrite()> usually
maps to the operating system's C<write()> function and makes sure that
no other process writes to the same log file while C<write()> is busy.
Might safe you from having to use other synchronisation measures like
semaphores (see: Synchronized appender).
=item umask
Specifies the C<umask> to use when creating the file, determining
the file's permission settings.
If set to C<0022> (default), new
files will be created with C<rw-r--r--> permissions.
If set to C<0000>, new files will be created with C<rw-rw-rw-> permissions.
=item owner
If set, specifies that the owner of the newly created log file should
be different from the effective user id of the running process.
Only makes sense if the process is running as root.
Both numerical user ids and user names are acceptable.
Log4perl does not attempt to change the ownership of I<existing> files.
=item group
If set, specifies that the group of the newly created log file should
be different from the effective group id of the running process.
Only makes sense if the process is running as root.
Both numerical group ids and group names are acceptable.
Log4perl does not attempt to change the group membership of I<existing> files.
=item utf8
If you're printing out Unicode strings, the output filehandle needs
to be set into C<:utf8> mode:
my $app = Log::Log4perl::Appender::File->new(
filename => 'file.log',
mode => 'append',
utf8 => 1,
);
=item binmode
To manipulate the output filehandle via C<binmode()>, use the
binmode parameter:
my $app = Log::Log4perl::Appender::File->new(
filename => 'file.log',
mode => 'append',
binmode => ":utf8",
);
A setting of ":utf8" for C<binmode> is equivalent to specifying
the C<utf8> option (see above).
=item recreate
Normally, if a file appender logs to a file and the file gets moved to
a different location (e.g. via C<mv>), 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
( run in 3.432 seconds using v1.01-cache-2.11-cpan-98e64b0badf )