ad_log_rate_limited (public)
ad_log_rate_limited [ -key key ] [ -interval interval ] severity \
messageDefined in packages/acs-tcl/tcl/utilities-procs.tcl
Log a message at most once per interval for the supplied key and severity, shared across connection threads of this server. Log the first occurrence immediately. Suppress subsequent calls within the interval and report their count with the next emitted message. The emitted message is the current call's message; suppressed message texts are not retained.
- Switches:
- -key (optional)
- stable identifier for the group of related messages
- -interval (optional, integer, defaults to
"60")- minimum interval between notices, in seconds; must be positive
- Parameters:
- severity (required)
- severity passed to ad_log
- message (required)
- message passed to ad_log
- Returns:
- 1 if ad_log was called, or 0 if the message was suppressed
- Author:
- Gustaf Neumann
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: if {$interval <= 0} { error "-interval must be greater than zero" } set mutex [nsv_get ad_log_rate_limited mutex] set state_key [list state $severity $key] set report_suppressed -1 ns_mutex eval $mutex { set now [clock seconds] if {![nsv_exists ad_log_rate_limited $state_key]} { nsv_set ad_log_rate_limited $state_key [list $now 0] set report_suppressed 0 } else { lassign [nsv_get ad_log_rate_limited $state_key] last_log suppressed if {$now - $last_log >= $interval || $now < $last_log} { nsv_set ad_log_rate_limited $state_key [list $now 0] set report_suppressed $suppressed } else { incr suppressed nsv_set ad_log_rate_limited $state_key [list $last_log $suppressed] } } } if {$report_suppressed < 0} { return 0 } if {$report_suppressed > 0} { append message " ($report_suppressed additional messages suppressed since previous log)" } # # Log after releasing the limiter mutex. # ad_log $severity $message return 1XQL Not present: PostgreSQL, Oracle Generic XQL file: packages/acs-tcl/tcl/utilities-procs.xql