MAN page from RedHat EL 8 perl-Log-Log4perl-1.50-1.el8.noarch.rpm


Section: User Contributed Perl Documentation (3)
Updated: 2020-07-22


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


    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");


This is a simple appender for writing to a file.

The "log()" method takes a single scalar. If a newline charactershould terminate the message, it has to be added explicitly.

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

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


Name of the log file.
Messages will be append to the file if $mode is set to thestring "append". Will clobber the fileif set to "clobber". If it is "pipe", the file will be understoodas executable to pipe output to. Default mode is "append".
"autoflush", if set to a true value, triggers flushing the dataout to the file on every call to "log()". "autoflush" is on by default.
"syswrite", if set to a true value, makes sure that the appender usessyswrite() instead of print() to log the message. "syswrite()" usuallymaps to the operating system's "write()" function and makes sure thatno other process writes to the same log file while "write()" is busy.Might safe you from having to use other synchronisation measures likesemaphores (see: Synchronized appender).
Specifies the "umask" to use when creating the file, determiningthe file's permission settings.If set to 0022 (default), newfiles will be created with "rw-r--r--" permissions.If set to 0000, new files will be created with "rw-rw-rw-" permissions.
If set, specifies that the owner of the newly created log file shouldbe 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 existing files.
If set, specifies that the group of the newly created log file shouldbe 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 existing files.
If you're printing out Unicode strings, the output filehandle needsto be set into ":utf8" mode:

    my $app = Log::Log4perl::Appender::File->new(      filename  => 'file.log',      mode      => 'append',      utf8      => 1,    );
To manipulate the output filehandle via "binmode()", use thebinmode parameter:

    my $app = Log::Log4perl::Appender::File->new(      filename  => 'file.log',      mode      => 'append',      binmode   => ":utf8",    );

A setting of ``:utf8'' for "binmode" is equivalent to specifyingthe "utf8" option (see above).

Normally, if a file appender logs to a file and the file gets moved toa different location (e.g. via "mv"), the appender's open file handlewill 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 nameand start logging into it. If the "recreate" option is set to a true value,"Log::Log4perl::Appender::File" will do exactly that. It defaults tofalse. Check the "recreate_check_interval" option for performanceoptimizations with this feature.

In "recreate" mode, the appender has to continuously check if thefile it is logging to is still in the same location. This check isfairly expensive, since it has to call "stat" on the file name andfigure out if its inode has changed. Doing this with every callto "log" can be prohibitively expensive. Setting it to a positiveinteger value N will only check the file every N seconds. It defaults to 30.

This obviously means that the appender will continue writing toa moved file until the next check occurs, in the worst casethis will happen "recreate_check_interval" seconds after the filehas been moved or deleted. If this is undesirable,setting "recreate_check_interval" to 0 will have theappender check the file with every call to "log()".

In "recreate" mode, if this option is set to a signal name(e.g. ``USR1''), the appender will recreate a missing logfilewhen it receives the signal. It uses less resources than constantpolling. The usual limitation with perl's signal handling apply.Check the FAQ for using this option with the log rotatingutility "newsyslog".
The popular log rotating utility "newsyslog" expects a pid filein order to send the application a signal when its logs havebeen rotated. This option expects a path to a file where the pidof the currently running application gets written to.Check the FAQ for using this option with the log rotatingutility "newsyslog".
The file appender typically creates its logfile in its constructor, Log4perl "init()" time. This is desirable for most use cases, becauseit makes sure that file permission problems get detected right away, andnot after days/weeks/months of operation when the appender suddenly needsto log something and fails because of a problem that was obvious atstartup.

However, there are rare use cases where the file shouldn't be createdat Log4perl "init()" time, e.g. if the appender can't be used by the currentuser although it is defined in the configuration file. If you set"create_at_logtime" to a true value, the file appender will try to createthe file at log time. Note that this setting lets permission problemssit undetected until log time, which might be undesirable.

If you want Log4perl to print a header into every newly opened(or re-opened) logfile, set "header_text" to either a stringor a subroutine returning a string. If the message doesn't have a newline,a newline at the end of the header will be provided.
If this this option is set to true,the directory path will be created if it does not exist yet.
Specifies the "umask" to use when creating the directory, determiningthe directory's permission settings.If set to 0022 (default), newdirectory will be created with "rwxr-xr-x" permissions.If set to 0000, new directory will be created with "rwxrwxrwx" permissions.

Design and implementation of this module has been greatly inspired byDave Rolsky's "Log::Dispatch" appender framework. 


Copyright 2002-2013 by Mike Schilli <>and Kevin Goess <>.

This library is free software; you can redistribute it and/or modifyit under the same terms as Perl itself. 


Please contribute patches to the project on Github:

Send bug reports or requests for enhancements to the authors via our

MAILING LIST (questions, bug reports, suggestions/patches)

Authors (please contact them via the list above, not directly):Mike Schilli <>,Kevin Goess <>

Contributors (in alphabetical order):Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, HuttonDavidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, AnthonyFoiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, AndyGrundman, Paul Harrington, Alexander Hartmaier David Hull,Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope,Lars Thegler, David Viner, Mac Yang.




This document was created byman2html,using the manual pages.