14 <tr><td colspan="2"><hr></td></tr> 15 <tr><td class="skipped" colspan="2">Skipped * bytes</td><tr>';
20 protected function format($prio,$context){
21 if(strlen($result = parent::format($prio,$context)) > $this->maxSize){
22 $result = substr($result,0,$this->maxSize);
23 $result = substr($result,0,strrpos($result,
"</tr>\n<tr>") + 5);
30 if($size = filesize($this->filename))
try{
31 \Rsi\File::write($this->timeFilename,date(
'c'),0666);
33 fseek($f = fopen($this->indexFilename,
'r'),$skipped = max(0,filesize($this->indexFilename) - $this->maxSize));
34 $index = fread($f,$this->maxSize);
36 file_put_contents($this->indexFilename,null);
37 if($skipped) $index = substr($index,strpos($index,
"\n<tr"));
39 fseek($f = fopen($this->filename,
'r'),$skipped = max(0,$size - $this->maxSize));
40 $log = fread($f,$this->maxSize);
42 file_put_contents($this->filename,null);
44 $log = str_replace(
'*',$skipped,$this->templateSkipped) . substr($log,$extra = strpos($log,
"\n<tr"));
47 if($log) $result = $this->_log->component(
'mail')->send(
49 $this->to ?: ini_get(
'sendmail_from'),
50 str_replace(
'*',$host = \
Rsi\Http::host(),$this->subject),
51 strtr(\
Rsi\File::read($this->templateFile),[
52 '[time]' => date(
'Y-m-d H:i:s'),
54 '[ip]' => $_SERVER[
'SERVER_ADDR'] ?? gethostbyname($host),
62 if($this->_log->fred->debug)
throw $e;
68 public function add($prio,$message,$context){
69 parent::add($prio,$message,$context);
70 $age = time() - $this->_log->filemtime($this->timeFilename);
72 (($prio >= $this->threshold) && ($prio < \
Rsi\
Fred\
Log::CUSTOM) && ($age >= $this->interval * 60)) ||
73 ($age > $this->deadline * 60)
78 if(!parent::getFilename()) $this->_filename = \Rsi\File::tempDir() .
"maillog-{$this->name}.tmp";
83 return $this->filename .
'.time';
$interval
Minimal mail interval (minutes).
const CUSTOM
Everything above this is only logged when exactly matched.
$templateSkipped
Template when skipping (an asterisk is replaced with the number of bytes skipped).
add($prio, $message, $context)
$from
Sender (defaults to default From address).
Framework for Rapid and Easy Development.
$to
Send mail to this address (or array for multiple; defaults to default From address).
$deadline
Maximum mail interval (minutes).
$subject
Subject for the mail (an asterisk is replaced with the host name).
$templateFile
File with mail template ([time], [host], [ip] of server, [index] and.