diff options
author | Peter Palfrader <peter@palfrader.org> | 2003-01-14 05:26:14 +0000 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2003-01-14 05:26:14 +0000 |
commit | eb4acbf430ba48cf496dac77948eb0d2b8536786 (patch) | |
tree | 49079dd8f591e0ae4d43663a85c03e1e6a4c9e27 | |
parent | f46e990efedb3d5d8ef94e833e0fa676047da1fe (diff) |
First go at sane logging
-rw-r--r-- | Echolot/Log.pm | 106 | ||||
-rw-r--r-- | NEWS | 1 |
2 files changed, 107 insertions, 0 deletions
diff --git a/Echolot/Log.pm b/Echolot/Log.pm new file mode 100644 index 0000000..9eb7d9f --- /dev/null +++ b/Echolot/Log.pm @@ -0,0 +1,106 @@ +package Echolot::Log; + +# (c) 2002 Peter Palfrader <peter@palfrader.org> +# $Id: Log.pm,v 1.1 2003/01/14 05:26:14 weasel Exp $ +# + +=pod + +=head1 Name + +Echolot::Globals - echolot global variables + +=head1 DESCRIPTION + +=cut + +use strict; +use Carp qw{}; +use Log::Dispatch::File; +use Log::Dispatch; + +my $LOG; + +my @monnames = qw{Jan Feb Mar Arp May Jun Jul Aug Sep Oct Nov Dec}; +sub header_log(%) { + my (%msg) = @_; + + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); + my $time = sprintf("%s %02d %02d:%02d:%02d", + $monnames[$mon], + $mday, + $hour, $min, $sec); + my $logstring = $time.' '. + '['.uc($msg{'level'}).']'. ' '. + $msg{'message'}."\n"; + $logstring =~ s/(?<=.)^/ /mg; + return $logstring; +}; + +sub init(%) { + my (%args) = @_; + + $LOG = Log::Dispatch->new( callbacks => \&header_log ); + $LOG->add( Log::Dispatch::File->new( + name => 'file1', + min_level => 'debug', + filename => 'pingd.log', + mode => 'append', + )); +}; + +#sub log() { +# return $LOG; +#}; + +sub debug($) { + $LOG->debug(@_); +}; +sub info($) { + $LOG->info(@_); +}; +sub notice($) { + $LOG->notice(@_); +}; +sub warn($) { + $LOG->warning(@_); +}; +sub warning($) { + $LOG->warning(@_); +}; +sub error($) { + $LOG->error(@_); +}; +sub critical($) { + $LOG->critical(@_); +}; +sub alert($) { + $LOG->alert(@_); +}; +sub emergency($) { + $LOG->emergency(@_); +}; + +sub logdie($) { + my ($msg) = @_; + critical($msg); + die($msg); +}; +sub cluck($) { + my ($msg) = @_; + my $longmess = Carp::longmess(); + $longmess =~ s/^/ /mg; + $msg .= "\n".$longmess; + warning($msg); +}; +sub confess($) { + my ($msg) = @_; + my $longmess = Carp::longmess(); + $longmess =~ s/^/ /mg; + $msg .= "\n".$longmess; + critical($msg); + die($msg); +}; + +1; +# vim: set ts=4 shiftwidth=4: @@ -2,6 +2,7 @@ Changes in * first go at sane loggin fixme: new requirements fixme: make logging configureable + fixme: reopen log on SIGHUP Changes in version 2.0.8 - 2003-01-13 * Work around a bug that let pingd die in certain random cases when |