From 84c1e9ab4892fe8355324d18816fb8188525951f Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Wed, 9 Feb 2000 20:15:51 +0000 Subject: [PATCH] added log() function to allow generic logging added trap routines for __DIE__ and __WARN__ to log die() and warn() output --- src/lib/Spong/Log.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/Spong/Log.pm b/src/lib/Spong/Log.pm index d3ef7e9..ce1393c 100755 --- a/src/lib/Spong/Log.pm +++ b/src/lib/Spong/Log.pm @@ -32,6 +32,12 @@ my($errlog); &set_debug_context(); &set_error_context(); +# Setup intercept routines for die and warn in order to log their infomation +$main::SIG{'__DIE__'} = sub { if ( defined $^S && ! $^S && defined $errlog) + { $errlog->log("die(): " . $_[0]); } }; +$main::SIG{'__WARN__'} = sub { if ( defined $^S && ! $^S && defined $errlog) + { $errlog->log("warn(): " . $_[0]); } }; + # This function is used to set the debug logging context sub set_debug_context { @@ -80,13 +86,19 @@ sub close_error_log { undef $errlog; } -sub error { +sub log { my( $message ) = @_; # if the error logger is not defined, create it. if ( ! defined $errlog ) { &open_error_log(); } + + $errlog->log("$message"); +} + +sub error { + my( $message ) = @_; - $errlog->log("Error: $message"); + &log("Error: $message"); } sub debug { -- 2.30.2