[interchange-cvs] interchange - heins modified lib/Vend/Util.pm

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Thu Jul 15 13:29:23 EDT 2004


User:      heins
Date:      2004-07-15 17:29:23 GMT
Modified:  lib/Vend Util.pm
Log:
* Add ability to specify a different target file with logError, by
  prepending an option hash:

  	   logError({ file => 'other.log' }, "msg %s", $var);

* Make logOnce slightly more efficent (and more readable).

Revision  Changes    Path
2.75      +27 -13    interchange/lib/Vend/Util.pm


rev 2.75, prev_rev 2.74
Index: Util.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Util.pm,v
retrieving revision 2.74
retrieving revision 2.75
diff -u -r2.74 -r2.75
--- Util.pm	28 Jun 2004 21:37:50 -0000	2.74
+++ Util.pm	15 Jul 2004 17:29:23 -0000	2.75
@@ -1,6 +1,6 @@
 # Vend::Util - Interchange utility functions
 #
-# $Id: Util.pm,v 2.74 2004/06/28 21:37:50 mheins Exp $
+# $Id: Util.pm,v 2.75 2004/07/15 17:29:23 mheins Exp $
 # 
 # Copyright (C) 2002-2003 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -87,7 +87,7 @@
 use Vend::File;
 use subs qw(logError logGlobal);
 use vars qw($VERSION @EXPORT @EXPORT_OK);
-$VERSION = substr(q$Revision: 2.74 $, 10);
+$VERSION = substr(q$Revision: 2.75 $, 10);
 
 my $Eval_routine;
 my $Eval_routine_file;
@@ -530,7 +530,7 @@
 
     $r = '';
     for ($i = 0;  $i < $len;  ++$i) {
-	$r .= substr($random_chars, int(rand(length($random_chars))), 1);
+		$r .= substr($random_chars, int(rand(length($random_chars))), 1);
     }
     $r;
 }
@@ -707,7 +707,7 @@
 		close(MVLOGDATA) or die "close\n";
     };
     if ($@) {
-		::logError ("Could not %s log file '%s': %s\nto log this data:\n%s",
+		logError ("Could not %s log file '%s': %s\nto log this data:\n%s",
 				$@,
 				$file,
 				$!,
@@ -1041,7 +1041,7 @@
 	$file =~ s#\s+$##;
 	$file =~ s#\.html?$##;
 	if($file =~ m{\.\.} and $file =~ /\.\..*\.\./) {
-		::logError( "Too many .. in file path '%s' for security.", $file );
+		logError( "Too many .. in file path '%s' for security.", $file );
 		$file = find_special_page('violation');
 	}
 	$file =~ s#//+#/#g;
@@ -1420,7 +1420,7 @@
 		}
 		if($Vend::Cfg->{UserDB} and $Vend::Cfg->{UserDB}{log_failed}) {
 			my $besthost = $CGI::remote_host || $CGI::remote_addr;
-			::logError("auth error host=%s ip=%s script=%s page=%s",
+			logError("auth error host=%s ip=%s script=%s page=%s",
 							$besthost,
 							$CGI::remote_addr,
 							$CGI::script_name,
@@ -1683,7 +1683,18 @@
 
 sub logError {
     my $msg = shift;
-	return unless defined $Vend::Cfg;
+	return unless $Vend::Cfg;
+
+	my $opt;
+	if(ref $_[0]) {
+		$opt = shift(@_);
+	}
+	else {
+		$opt = {};
+	}
+
+	$opt->{file} ||= $Vend::Cfg->{ErrorFile};
+
 	if(@_) {
 		$msg = errmsg($msg, @_);
 	}
@@ -1694,11 +1705,11 @@
 
     $msg = format_log_msg($msg) unless $msg =~ s/^\\//;
 
-	$Vend::Errors .= $msg if ($Vend::Cfg->{DisplayErrors} ||
-							  $Global::DisplayErrors);
+	$Vend::Errors .= $msg
+		if $Vend::Cfg->{DisplayErrors} || $Global::DisplayErrors;
 
     eval {
-		open(MVERROR, ">>$Vend::Cfg->{ErrorFile}")
+		open(MVERROR, ">> $opt->{file}")
 											or die "open\n";
 		lockfile(\*MVERROR, 1, 1)		or die "lock\n";
 		seek(MVERROR, 0, 2)				or die "seek\n";
@@ -1711,7 +1722,7 @@
 		logGlobal ({ level => 'info' },
 					"Could not %s error file %s: %s\nto report this error: %s",
 					$@,
-					$Vend::Cfg->{ErrorFile},
+					$opt->{file},
 					$!,
 					$msg,
 				);
@@ -1731,9 +1742,12 @@
 # First argument should be log type (see above map).
 # Rest of arguments are same as if calling log routine directly.
 sub logOnce {
-	return if exists $logOnce_cache{"@_"};
+	my $tag = join "", @_;
+	return if exists $logOnce_cache{$tag};
 	my $log_sub = $log_sub_map{ lc(shift) } || $log_sub_map{error};
-	$log_sub->(@_) and ++$logOnce_cache{"@_"};
+	my $status = $log_sub->(@_);
+	$logOnce_cache{$tag} = 1;
+	return $status;
 }
 
 








More information about the interchange-cvs mailing list