SYNOPSIS

 use Log::Agent;
 require Log::Agent::Driver::File;

 my $driver = Log::Agent::Driver::File->make(
     -prefix     => "prefix",
     -duperr     => 1,
     -stampfmt   => "own",
     -showpid    => 1,
     -magic_open => 0,
     -channels   => {
        error   => '/tmp/output.err',
        output  => 'log.out',
        debug   => '../appli.debug',
     },
     -chanperm   => {
        error   => 0777,
        output  => 0666,
        debug   => 0644
     }
 );
 logconfig(-driver => $driver);

DESCRIPTION

The file logging driver redirects logxxx() operations to specified files, one per channel usually (but channels may go to the same file).

The creation routine make() takes the following arguments: Specifies where channels go. The supplied hash maps channel names (\*(C`error\*(C', \*(C`output\*(C' and \*(C`debug\*(C') to filenames. When \*(C`-magic_open\*(C' is set to true, filenames are allowed magic processing via perl's open(), so this allows things like: -channels => { 'error' => '>&FILE', 'output' => '>newlog', # recreate each time, don't append 'debug' => '|mailx -s whatever user', } If a channel (e.g. 'output') is not specified, it will go to the 'error' channel, and if that one is not specified either, it will go to \s-1STDERR\s0 instead. If you have installed the additional \*(C`Log::Agent::Rotate\*(C' module, it is also possible to override any default rotating policy setup via the \*(C`-rotate\*(C' argument: instead of supplying the channel as a single string, use an array reference where the first item is the channel file, and the second one is the \*(C`Log::Agent::Rotate\*(C' configuration: my $rotate = Log::Agent::Rotate->make( -backlog => 7, -unzipped => 2, -max_write => 100_000, -is_alone => 1, );

my $driver = Log::Agent::Driver::File->make( ... -channels => { 'error' => ['errors', $rotate], 'output' => ['output, $rotate], 'debug' => ['>&FILE, $rotate], # WRONG }, -magic_open => 1, ... ); In the above example, the rotation policy for the \*(C`debug\*(C' channel will not be activated, since the channel is opened via a magic method. See Log::Agent::Rotate for more details. Specifies the file permissions for the channels specified by \*(C`-channels\*(C'. The arguemtn is a hash ref, indexed by channel name, with numeric values. This option is only necessary to override the default permissions used by Log::Agent::Channel::File. It is generally better to leave these permissive and rely on the user's umask. See \*(L"umask\*(R" in perlfunc\|(3) for more details.. When true, all messages normally sent to the \*(C`error\*(C' channel are also copied to the \*(C`output\*(C' channel with a prefixing made to clearly mark them as such: \*(L"\s-1FATAL:\s0 \*(R" for logdie(), logcroak() and logconfess(), \*(L"\s-1ERROR:\s0 \*(R" for logerr() and \*(L"\s-1WARNING:\s0 \*(R" for logwarn(). Note that the \*(L"duplicate\*(R" is the original error string for logconfess() and logcroak(), and is not strictly identical to the message that will be logged to the \*(C`error\*(C' channel. This is a an accidental feature. Default is false. This switch supersedes both \*(C`-duperr\*(C' and \*(C`-channels\*(C' by defining a single file for all the channels. This switch supersedes \*(C`-chanperm\*(C' by defining consistent for all the channels. When true, channel filenames beginning with '>' or '|' are opened using Perl's open(). Otherwise, sysopen() is used, in append mode. Default is false. The application prefix string to prepend to messages. This sets a default logfile rotation policy. You need to install the additional \*(C`Log::Agent::Rotate\*(C' module to use this switch. object is the \*(C`Log::Agent::Rotate\*(C' instance describing the default policy for all the channels. Only files which are not opened via a so-called magic open can be rotated. If set to true, the \s-1PID\s0 of the process will be appended within square brackets after the prefix, to all messages. Default is false. Specifies the time stamp format to use. By default, my \*(L"own\*(R" format is used. The following formats are available: date "[Fri Oct 22 16:23:10 1999]" none own "99/10/22 16:23:10" syslog "Oct 22 16:23:10". You may also specify a \s-1CODE\s0 ref: that routine will be called every time we need to compute a time stamp. It should not expect any parameter, and should return a string.

CHANNELS

All the channels go to the specified files. If a channel is not configured, it is redirected to 'error', or \s-1STDERR\s0 if no 'error' channel was configured either.

Two channels not opened via a magic open and whose logfile name is the same are effectively shared, i.e. the same file descriptor is used for both of them. If you supply distinct rotation policies (e.g. by having a default policy, and supplying another policy to one of the channel only), then the final rotation policy will depend on which one was opened first. So don't do that.

CAVEAT

Beware of chdir(). If your program uses chdir(), you should always specify logfiles by using absolute paths, otherwise you run the risk of having your relative paths become invalid: there is no anchoring done at the time you specify them. This is especially true when configured for rotation, since the logfiles are recreated as needed and you might end up with many logfiles scattered throughout all the directories you chdir()ed to.

Logging channels with the same pathname are shared, i.e. they are only opened once by \*(C`Log::Agent::Driver::File\*(C'. Therefore, if you specify different rotation policy to such channels, the channel opening order will determine which of the policies will be used for all such shared channels. Such errors are flagged at runtime with the following message:

Rotation for 'logfile' may be wrong (shared with distinct policies)

emitted in the logs upon subsequent sharing.

AUTHORS

Originally written by Raphael Manfredi <[email protected]>, currently maintained by Mark Rogaski <[email protected]>.

Thanks to Joseph Pepin for suggesting the file permissions arguments to make().

LICENSE

Copyright (C) 1999 Raphael Manfredi. Copyright (C) 2002 Mark Rogaski; all rights reserved.

See Log::Agent\|(3) or the \s-1README\s0 file included with the distribution for license information.

RELATED TO Log::Agent::Driver::File…

Log::Agent::Driver\|(3), Log::Agent\|(3), Log::Agent::Rotate\|(3).