| Log-Fine documentation | Contained in the Log-Fine distribution. |
Log::Fine::Handle::Syslog - Output log messages to syslog
Provides logging to syslog()
use Log::Fine;
use Log::Fine::Handle::Syslog;
use Sys::Syslog;
# Get a new logger
my $log = Log::Fine->logger("foo");
# register a syslog handle
my $handle = Log::Fine::Handle::Syslog
->new( name => 'syslog0',
mask => LOGMASK_EMERG | LOGMASK_ALERT | LOGMASK_CRIT | LOGMASK_ERR | LOGMASK_WARNING | LOGMASK_NOTICE | LOGMASK_INFO,
ident => $0,
logopts => 'pid',
facility => LOG_LEVEL0 );
# register the handle
$log->registerHandle($handle);
# log something
$log->(INFO, "Opened new log handle");
Log::Fine::Handle::Syslog provides logging via the standard UNIX syslog facility. For more information, it is highly recommended that you read the Sys::Syslog documentation.
See msgWrite in Log::Fine::Handle
Note that this method does not make use of a formatter as this is handled by the syslog facility.
Please report any bugs or feature requests to
bug-log-fine-handle-syslog at rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Log-Fine.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc Log::Fine
You can also look for information at:
$Id: c3d08d128e127c6efd71eb2184cc35de3f6eec5e $
Christopher M. Fuhrman, <cfuhrman at panix.com>
perl, syslog, Sys::Syslog
Copyright (c) 2008, 2010 Christopher M. Fuhrman, All rights reserved.
This program is free software licensed under the...
The BSD License
The full text of the license can be found in the LICENSE file included with this module.
| Log-Fine documentation | Contained in the Log-Fine distribution. |
use strict; use warnings; package Log::Fine::Handle::Syslog; use base qw( Log::Fine::Handle ); use File::Basename; use Log::Fine; use Sys::Syslog 0.13 qw( :standard :macros ); our $VERSION = $Log::Fine::Handle::VERSION; # Constant: LOG_MAPPING # # Maps Log::Fine LOG_LEVELS to Sys::Syslog equivalents use constant LOG_MAPPING => { 0 => LOG_EMERG, 1 => LOG_ALERT, 2 => LOG_CRIT, 3 => LOG_ERR, 4 => LOG_WARNING, 5 => LOG_NOTICE, 6 => LOG_INFO, 7 => LOG_DEBUG, }; # Private Methods # -------------------------------------------------------------------- { my $flag = 0; # Getter/Setter for flag sub _flag { $flag = 1 if (defined $_[0] and $_[0] =~ /\d/ and $_[0] > 0); return $flag; } } # --------------------------------------------------------------------
sub msgWrite { my $self = shift; my $lvl = shift; my $msg = shift; my $skip = shift; # NOT USED my $map = LOG_MAPPING; # write to syslog syslog($map->{$lvl}, $msg); # Victory! return $self; } # msgWrite() # -------------------------------------------------------------------- ## # Initializes our object sub _init { my $self = shift; # call the super object $self->SUPER::_init(); # Make sure we have one and only one syslog object defined $self->_fatal( sprintf("One and _only_ one %s object may be defined", ref $self)) if _flag(); # set ident $self->{ident} = basename $0; # set the default logopts (to be passed to Sys::Syslog::openlog() $self->{logopts} = "pid" unless (defined $self->{logopts} and $self->{logopts} =~ /\w+/); # set the default facility $self->{facility} = LOG_LOCAL0 unless (defined $self->{facility} and $self->{facility} =~ /\w+/); # open the syslog connection and set flag openlog($self->{ident}, $self->{logopts}, $self->{facility}); _flag(1); # Victory! return $self; } # _init() ## # called when this object is destroyed sub DESTROY { closelog(); }
1; # End of Log::Fine::Handle::Syslog