5 class Stats extends \Rsi\Fred\Log\Handler{
15 public $message =
'Message "[message]" ([filename]@[lineNo]) occurred [threshold] times in the last [ttl] seconds';
18 protected function same($new_message,$old_message){
19 return (similar_text($new_message,$old_message,$perc) >= $this->charThreshold) || ($perc >=
$this->percThreshold);
23 return $this->_log->component(
'mail')->send(
25 $this->to ?: ini_get(
'sendmail_from'),
26 str_replace(
'*',\
Rsi\Http::host(),$this->subject),
27 strtr($this->message,[
29 '[lineNo]' => $line_no ?: 0,
31 '[threshold]' => $this->threshold,
38 if($this->filename)
try{
39 $records = \Rsi\File::unserialize($this->filename,[]);
41 foreach($records as $index => &$record){
43 foreach($record[
'times'] as $time)
if($time > $limit) $times[] = $time;
44 if($times) $record[
'times'] = $times;
45 else unset($records[$index]);
49 $line_no = $context[
'lineNo'] ?? null;
50 foreach($records as $index => &$record)
if(
52 ($record[
'lineNo'] == $line_no) &&
55 if((count($record[
'times']) >= $this->threshold) && $this->
send(
$filename,$line_no,
$message)) $record[
'times'] = [];
56 $record[
'times'][] = time();
62 \Rsi\File::serialize($this->filename,$records);
65 if($this->_log->fred->debug)
throw $e;
$filename
File to store messages.
$percThreshold
Minimum percentage to match.
$subject
Subject for the mail (an asterisk is replaced with the host name).
$threshold
Send mail after this number of messages within the TTL.
send($filename, $line_no, $message)
$from
Sender (defaults to default From address).
$to
Send mail to this address (or array for multiple; defaults to default From address).
$charThreshold
Minimum number of charactes to match, or:
same($new_message, $old_message)
$ttl
Time to keep messages in memory.
add($prio, $message, $context)