| Log-Syslog-Fast documentation | Contained in the Log-Syslog-Fast distribution. |
Log::Syslog::Fast::Simple - Wrapper around Log::Syslog::Fast that adds some flexibility at the expense of additional runtime overhead.
use Log::Syslog::Fast::Simple;
# Simple usage:
$logger = Log::Syslog::Fast::Simple->new;
$logger->send("log message");
# More customized usage:
$logger = Log::Syslog::Fast::Simple->new(
loghost => 'myloghost',
port => 6666,
facility => LOG_LOCAL2,
severity => LOG_INFO,
sender => 'mymachine',
name => 'myapp',
);
$logger->send("log message", time, LOG_LOCAL3, LOG_DEBUG);
This module wraps Log::Syslog::Fast to provide a constructor with reasonable defaults and a send() method that optionally accepts override parameters for facility and severity.
Create a new Log::Syslog::Fast::Simple object with given parameters (may be a hash or hashref). Takes the following named parameters which have the same meaning as in Log::Syslog::Fast.
Defaults to LOG_UDP
Defaults to 127.0.0.1
Defaults to 514
Defaults to LOG_LOCAL0
Defaults to LOG_INFO
Defaults to Sys::Hostname::hostname
Defaults to a cleaned $0
Send a syslog message through the configured logger. If $time is not provided, the current time is used. If $severity or $facility are not provided, the default provided at construction time is used.
Same as Log::Syslog::Fast.
Adam Thomason, <athomason@sixapart.com>
Copyright (C) 2009-2011 by Say Media, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
| Log-Syslog-Fast documentation | Contained in the Log-Syslog-Fast distribution. |
package Log::Syslog::Fast::Simple; use strict; use warnings; use Log::Syslog::Fast ':all'; use Sys::Hostname; require Exporter; our @ISA = qw(Exporter); our %EXPORT_TAGS = %Log::Syslog::Fast::EXPORT_TAGS; our @EXPORT_OK = @Log::Syslog::Fast::EXPORT_OK; our @EXPORT = qw(); use constant _LOGGERS => 0; use constant _ARGS => 1; use constant _PROTO => 0; use constant _HOSTNAME => 1; use constant _PORT => 2; use constant _FACILITY => 3; use constant _SEVERITY => 4; use constant _SENDER => 5; use constant _NAME => 6; sub new { my $what = shift; my $class = ref $what || $what; my $default_name = $0; $default_name =~ s,.*/,,; $default_name =~ s/[^\w.-_]//g; my $args = (@_ == 1 && ref $_[0] eq 'HASH') ? $_[0] : {@_}; $args->{proto} ||= LOG_UDP; $args->{hostname} ||= '127.0.0.1'; $args->{port} ||= 514; $args->{facility} ||= LOG_LOCAL0; $args->{severity} ||= LOG_INFO; $args->{sender} ||= Sys::Hostname::hostname; $args->{name} ||= $default_name; return bless [ [], # loggers [@{ $args }{qw/ proto hostname port facility severity sender name /}], ], $class; } sub send { my $severity = $_[3] || $_[0][_ARGS][_SEVERITY]; my $facility = $_[4] || $_[0][_ARGS][_FACILITY]; my $logger = $_[0][_LOGGERS][$facility][$severity]; if (!$logger) { my @args = @{ $_[0][_ARGS] }; $args[_FACILITY] = $facility; $args[_SEVERITY] = $severity; $logger = $_[0][_LOGGERS][$facility][$severity] = Log::Syslog::Fast->new(@args); } return $logger->send($_[1], $_[2] || time); } 1; __END__