8 <tr id='ix-[id]' class='prio[prio]'> 9 <td class='time'><a href='#[id]'>[time]</a></td> 10 <td class='prio'><a href='#[id]'>[name] ([prio])</a></td> 11 <td class='message'>[message]</td> 17 protected function value($value){
18 if($value === null)
return '<i>null</i>';
19 if($value ===
false)
return '<i>false</i>';
20 if($value ===
true)
return '<i>true</i>';
21 if($value ===
'')
return '<i>[empty string]</i>';
23 (is_string($value) && preg_match(
'/(^\\s| {2,}|\\s$)/',$value) && ($value = htmlspecialchars($value))) ||
24 (strpos($value = htmlspecialchars(trim(str_replace(
"Array\n(",
'array(',print_r($value,
true)))),
"\n") !==
false)
29 protected function format($prio,$context){
30 $this->_lastInsertId = $id = \Rsi\Str::random();
31 $result =
"<tr><td colspan='2'><a name='$id'>{$this->separator}</a></td></tr>\n";
32 foreach($context as $key => $value){
33 if($special = substr($key,0,1) ==
'*') $key = substr($key,1);
34 $class = ($special ?
'special ' :
'') . preg_replace(
'/\\W+/',
'-',$key);
35 if(($descr = $key) ==
'date/time') $descr =
"<a href='#ix-$id'>$descr</a>";
40 foreach($value as $record)
if(!is_array($record) || ($keys && (array_keys($record) !== $keys))){
44 else $keys = array_keys($record);
46 $html .=
"\t\t<tr><th></th><th>" . implode(
'</th><th>',array_map(
'htmlspecialchars',$keys)) .
"</th></tr>\n";
47 foreach($value as $index => $record){
48 $html .=
"\t\t<tr><th>" . htmlspecialchars($index) .
"</th>";
49 foreach($record as $data) $html .=
50 "<td" . (is_scalar($data) && preg_match(
'/^[\\d\\-:\\s]+$/',$data) ?
" class='number'" :
'') .
">" . $this->
value($data) .
"</td>";
54 else foreach($value as $key => $data) $html .=
55 "\t\t<tr><th>" . htmlspecialchars($key) .
"</th><td>" . $this->
value($data) .
"</td></tr>\n";
56 $html .=
"\t</table>";
58 if(strlen($result .=
"<tr class='$class'>\n\t<th>$descr</th>\n\t<td>" . ($html ?: $this->
value($value)) .
"</td>\n</tr>\n") > $this->maxSize){
59 $result .=
"<tr class='more'><td colspan='2'>...</td><tr>\n";
66 public function add($prio,$message,$context){
67 parent::add($prio,$message,$context);
68 if($index = $this->indexFilename) \Rsi\File::write($index,strtr($this->templateIndex,[
69 '[id]' => $this->_lastInsertId,
70 '[time]' => $this->_lastInsertTime,
72 '[name]' => array_search($prio,$this->_log->constants()),
73 '[message]' => htmlspecialchars($message)
78 return $this->filename .
'.index';
add($prio, $message, $context)
$templateIndex
Index template ([id] of item, [time], [prio], [name] of prio, and [message] are replaced).