| RWDE documentation | Contained in the RWDE distribution. |
Provides methods to log via syslog
Method to enable debug mode
Method to toggle debug mode
Determine if debug mode is currently set
Private Method
Open the syslog connection defined within the Configuration file
Log a message to syslog via the established syslog connection
A type and info are required
type is one of debug, info, notice, warning, err, crit, alert, emerg info is the desired log message
Take the type and the human readable message and print it to STDERR if debug is on
| RWDE documentation | Contained in the RWDE distribution. |
package RWDE::Logger; use strict; use warnings; use Error qw(:try); use Sys::Syslog qw(:standard :extended :macros); use RWDE::Configuration; use RWDE::Exceptions; our ($debug, $syslog_socket); use vars qw($VERSION); $VERSION = sprintf "%d", q$Revision: 507 $ =~ /(\d+)/;
sub set_debug { $debug = 1; return; }
sub toggle_debug { $debug = ($debug ? 0 : 1); return; }
sub is_debug { return $debug; }
sub _init_syslog { # open syslog connection my $result = setlogsock 'unix'; if (not defined $result) { throw RWDE::DevelException({ info => 'Could not connect to syslog facility' }); } $syslog_socket = $result; my $log_filename = lc(RWDE::Configuration->ServiceName); openlog($log_filename, 'cons,pid', LOG_LOCAL0); return (); }
sub syslog_msg { my ($self, $type, $info) = @_; if (!($syslog_socket)) { _init_syslog(); } my ($package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask) = caller(1); my %valid_level = ( debug => 1, info => 1, notice => 1, warning => 1, err => 1, crit => 1, alert => 1, emerg => 1 ); if (not defined $valid_level{$type}) { $type = 'info'; } if (not defined $info) { my ($package, $filename, $line) = caller(1); $info = "No message sent to syslog from $filename Line: $line!"; } if (defined($package) && defined($subroutine)) { $info = "$package=>$subroutine ($info)"; } syslog($type, '%s', $info); debug_info($type, $info); return; }
sub debug_info { my ($type, $info) = @_; if ($debug) { my $d = scalar localtime; print "$d: $type -- $info\n"; } return (); } 1;