26 foreach($this->handlers as &$config){
27 if(!$config) $config = [];
28 $prio = $config[
'prio'] ?? null;
29 if(!array_key_exists(
'prios',$config) || ($prio !== null))
30 $config[
'prios'] = array_merge($config[
'prios'] ?? [],range($prio ?: self::DEBUG,self::CUSTOM - 1));
40 if(!is_array($this->handlers[$name])) $this->handlers[$name] = [];
41 if(!array_key_exists(null,$config =& $this->handlers[$name])){
42 $class_name = \Rsi\Record::get($config,
'className',__CLASS__ .
'\\Handler\\' . ucfirst($name));
43 $config[null] =
new $class_name($this,$config,$name);
52 public function has($name){
53 return array_key_exists($name,$this->handlers) ? $this->
handler($name) :
false;
56 protected function context($filename,$line_no,$context){
57 return is_array($filename)
59 : array_merge(array_filter([
'*filename' => $filename,
'*lineNo' => $line_no]),$context ?: []);
71 public function add($prio,$message,$filename = null,$line_no = null,$context = null){
72 if($this->
break && preg_match($this->
break,$message))
throw new \Exception(
'[break]');
73 if(!$this->_busy)
try{
76 foreach($this->handlers as $name => $config)
if(in_array($prio,$config[
'prios']))
try{
80 $context = ($filename ?: []) + [
'trace' => $message->getTraceAsString()];
81 $filename = $message->getFile();
82 $line_no = $message->getLine();
83 $message = $message->getMessage();
86 $subject = implode(
'#',[
87 \
Rsi\Record::get($context,
'remoteAddr') ?: $this->
component(
'security')->remoteAddr,
88 $_SERVER[
'HTTP_USER_AGENT'] ?? null,
89 is_string($filename) ? $filename : null,
92 foreach($this->ignore as $filter)
if(preg_match($filter,$subject))
return false;
94 foreach($this->
context($filename,$line_no,$context) as $key => $value){
95 if(substr($key,0,1) ==
'@') $value = call_user_func($value,$key = substr($key,1));
96 $parsed[$key] = $value;
99 $this->
handler($name)->add($prio,$message,$parsed);
102 if($this->_fred->debug)
throw $e;
106 $this->_busy =
false;
118 public function start($prio,$message,$filename = null,$line_no = null,$context = null){
119 $context = $this->
context($filename,$line_no,$context);
120 $this->_timers[$id = \Rsi\Str::random()] = compact(
'prio',
'message',
'context');
121 $this->
add($prio,$message,[
'*start' => $id] + $context);
134 public function stop($id,$prio = null,$message = null,$filename = null,$line_no = null,$context = null){
135 $timer = $this->_timers[$id] ?? [];
137 $prio === null ? $timer[
'prio'] ?? self::DEBUG : $prio,
138 $message === null ?
'[stop] ' . ($timer[
'message'] ?? null) : $message,
139 [
'*stop' => $id] + (($filename === null) && ($line_no === null) && ($context === null)
140 ? $timer[
'context'] ?? []
141 : $this->
context($filename,$line_no,$context)
150 public function __call($func_name,$params){
151 array_unshift($params,constant(
'self::' . strtoupper($func_name)));
152 call_user_func_array([$this,
'add'],$params);
155 public function __invoke($message,$filename = null,$line_no = null,$context = null){
156 $this->
add(self::DEBUG,$message,$filename,$line_no,$context);
const EMERGENCY
System is unusable.
const CUSTOM
Everything above this is only logged when exactly matched.
const INFO
Informational message.
start($prio, $message, $filename=null, $line_no=null, $context=null)
Add a timer start message to the log.
__call($func_name, $params)
stop($id, $prio=null, $message=null, $filename=null, $line_no=null, $context=null)
Stop a timer message.
add($prio, $message, $filename=null, $line_no=null, $context=null)
Add a message to the log.
const NOTICE
Normal, but significant, condition.
handler($name)
Get a handler.
has($name)
Check if the log has a specific handler.
const ERROR
Error conditions.
const CRITICAL
Critical conditions.
const ALERT
Action must be taken immediately.
const DEBUG
Debug-level message.
Framework for Rapid and Easy Development.
const WARNING
Warning conditions.
context($filename, $line_no, $context)
$handlers
Array with handlers (key = name, value = config).
$ignore
Reg-exp's for concatination of IP + '#' + user agent + '#' + filename + '#' + message to ignore...
component($name)
Get a component (local or default).
__invoke($message, $filename=null, $line_no=null, $context=null)
$break
Reg-exp for message to throw an Exception on.