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

interchange-core@interchange.redhat.com interchange-core@interchange.redhat.com
Tue Jan 15 20:55:00 2002


User:      jon
Date:      2002-01-16 01:54:09 GMT
Modified:  lib/Vend Util.pm
Log:
Add new logging front-end routine 'logOnce' that ignores
repeated identical log messages after the first occurrence
(for current page).

First parameter is the name of the log routine to call from
qw( data debug error global ); rest of arguments are whatever
logData, logDebug, logError, or logGlobal would normally get:

::logOnce('global', "Some '%s' string", $string);

Revision  Changes    Path
2.12      +23 -2     interchange/lib/Vend/Util.pm


rev 2.12, prev_rev 2.11
Index: Util.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Util.pm,v
retrieving revision 2.11
retrieving revision 2.12
diff -u -u -r2.11 -r2.12
--- Util.pm	2001/12/28 17:18:39	2.11
+++ Util.pm	2002/01/16 01:54:09	2.12
@@ -1,6 +1,6 @@
 # Vend::Util - Interchange utility functions
 #
-# $Id: Util.pm,v 2.11 2001/12/28 17:18:39 mheins Exp $
+# $Id: Util.pm,v 2.12 2002/01/16 01:54:09 jon Exp $
 # 
 # Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -53,6 +53,7 @@
 	logDebug
 	logError
 	logGlobal
+	logOnce
 	logtime
 	random_string
 	readfile
@@ -80,7 +81,7 @@
 use Safe;
 use subs qw(logError logGlobal);
 use vars qw($VERSION @EXPORT @EXPORT_OK);
-$VERSION = substr(q$Revision: 2.11 $, 10);
+$VERSION = substr(q$Revision: 2.12 $, 10);
 
 BEGIN {
 	eval {
@@ -1707,6 +1708,26 @@
 				);
     }
 }
+
+
+# Front-end to log routines that ignores repeated identical
+# log messages after the first occurrence
+my %logOnce_cache;
+my %log_sub_map = (
+	data	=> \&logData,
+	debug	=> \&logDebug,
+	error	=> \&logError,
+	global	=> \&logGlobal,
+);
+
+# 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 $log_sub = $log_sub_map{ lc(shift) } || $log_sub_map{error};
+	$log_sub->(@_) and ++$logOnce_cache{"@_"};
+}
+
 
 # Here for convenience in calls
 sub set_cookie {