5 class Mem extends \Rsi\Fred\Log\Handler{
13 public function add($prio,$message,$context){
14 if($this->maxSize && (count($this->messages) >= $this->maxSize))
15 $this->messages = array_slice($this->messages,$this->maxSize >> 1);
16 $this->messages[] = [
'time' => microtime(
true)] + compact(
'prio',
'message',
'context');
26 'start' => $this->_log->fred->startTime,
27 'end' => microtime(
true),
28 'file' => $_SERVER[
'REQUEST_URI'] ?? $_SERVER[
'PHP_SELF'] ?? null,
29 'mem' => memory_get_peak_usage(
true),
32 'code' => http_response_code(),
33 'session' => $_SESSION,
37 if($this->_log->fred->has(
'db')){
38 $db = $this->_log->fred->db;
39 $log[
'db'] = [
'count' => $db->queryCount,
'time' => $db->queryTime];
41 if(!$this->filename) $this->filename = \Rsi\File::tempDir() .
'log.dat';
43 $logs = array_slice(\
Rsi\File::unserialize($this->filename,[]) ?: [],1 - $this->
save,null,
true);
44 $logs[\Rsi\Str::random()] = $log;
45 \Rsi\File::serialize($this->filename,$logs,$this->mode);
48 \Rsi\File::unlink($this->filename);
49 $this->_log->component(
'log')->error($e);
add($prio, $message, $context)
$filename
Filename to store logs.
$maxSize
Maximum number of messages to store (empty = unlimited).
$save
Number of logs to save.