1 |
<?php |
2 |
|
3 |
/** |
4 |
* This file contains some core functions extending php. |
5 |
* Topic: basic runtime tracing |
6 |
* |
7 |
* @author Andreas Motl <andreas.motl@ilo.de> |
8 |
* @package org.netfrag.app |
9 |
* @name Tracer |
10 |
* |
11 |
*/ |
12 |
|
13 |
/** |
14 |
* $Id: Tracer.php,v 1.2 2003/04/05 21:19:38 joko Exp $ |
15 |
* |
16 |
* $Log: Tracer.php,v $ |
17 |
* Revision 1.2 2003/04/05 21:19:38 joko |
18 |
* + function event |
19 |
* - function warn |
20 |
* - function info |
21 |
* |
22 |
* Revision 1.1 2003/04/04 02:17:22 joko |
23 |
* initial commit |
24 |
* |
25 |
* |
26 |
*/ |
27 |
|
28 |
|
29 |
/** |
30 |
* --- Tracer |
31 |
* |
32 |
* @author Andreas Motl <andreas.motl@ilo.de> |
33 |
* @copyright (c) 2003 - All Rights reserved. |
34 |
* @license GNU LGPL (GNU Lesser General Public License) |
35 |
* |
36 |
* @link http://www.netfrag.org/~joko/ |
37 |
* @link http://www.gnu.org/licenses/lgpl.txt |
38 |
* |
39 |
* @package org.netfrag.app |
40 |
* @name Tracer |
41 |
* |
42 |
* |
43 |
*/ |
44 |
|
45 |
|
46 |
// lowlevel (just calls 'Dumper') |
47 |
Exporter::export_symbol('Tracer', array('add' => 'trace')); |
48 |
// highlevel (draws colored boxes) |
49 |
//Exporter::export_symbols('Tracer', array('warn', 'info')); |
50 |
|
51 |
|
52 |
class Tracer { |
53 |
|
54 |
function get_last($x) { |
55 |
global $_TRACE; |
56 |
return array_slice($_TRACE, -$x); |
57 |
} |
58 |
|
59 |
function box($dom_id = 'errorbox') { |
60 |
|
61 |
// FIXME: ie/mozilla? |
62 |
$errblock = html_div(); |
63 |
$errblock->set_id($dom_id); |
64 |
|
65 |
// V1 |
66 |
//$errblock->set_style('display:none;'); |
67 |
// V2 |
68 |
//$errblock->set_style('visibility:hidden; float:none; left: 50%; position:absolute; z-index:1;'); |
69 |
$errblock->set_style('visibility:hidden; position:absolute; z-index:1; left:5px; background: #eeeeee; margin-top:30px; padding:5px; border:1px solid black;'); |
70 |
|
71 |
//$errblock->add( html_br(), html_br() ); |
72 |
$errblock->add( html_b( "Events: (# " . sizeof($_TRACE) . ")" ) ); |
73 |
|
74 |
// FIXME: just use the last 50 entries... |
75 |
$lastX = Tracer::get_last(50); |
76 |
foreach ($lastX as $error) { |
77 |
$errblock->add( $error ); |
78 |
} |
79 |
//$errblock->add($_TRACE); |
80 |
|
81 |
return $errblock; |
82 |
} |
83 |
|
84 |
function out_plain_last10($dom_id) { |
85 |
$errblock = html_div(); |
86 |
$errblock->set_id($dom_id); |
87 |
$errblock->set_style('display:none;'); |
88 |
$lastX = Tracer::get_last(10); |
89 |
$errblock->add( join("\n---\n", $lastX) ); |
90 |
return $errblock; |
91 |
} |
92 |
|
93 |
function add($payload = null) { |
94 |
global $_TRACE; |
95 |
|
96 |
// V1 - array |
97 |
//if (is_array($payload)) { $payload = join('<br/>', $payload); } |
98 |
if (!is_array($_TRACE)) { $_TRACE = array(); } |
99 |
array_push($_TRACE, $payload); |
100 |
|
101 |
// V2 - container |
102 |
//if (!$_TRACE) { $_TRACE = container(); } |
103 |
//$_TRACE->add($payload); |
104 |
|
105 |
} |
106 |
|
107 |
function event($args = array()) { |
108 |
|
109 |
//print "event!!!<br/>"; |
110 |
//print Dumper($args); |
111 |
|
112 |
$type = $args[type]; |
113 |
$code = $args[code]; |
114 |
$error = $args[error]; |
115 |
$payload = $args[payload]; |
116 |
|
117 |
switch ($type) { |
118 |
case 'full': |
119 |
$output_order = array( 'message', 'component', 'file', 'line', 'level' ); |
120 |
break; |
121 |
case 'medium': |
122 |
$output_order = array( 'message', 'level', 'file', 'line' ); |
123 |
break; |
124 |
default: |
125 |
$output_order = array( 'message', 'level' ); |
126 |
break; |
127 |
} |
128 |
|
129 |
// dispatch color by level |
130 |
if ($code <= 8) { |
131 |
$color = '#eeeeee'; |
132 |
} elseif ($code == 512) { |
133 |
$color = 'orange'; |
134 |
} elseif ($code == 1024) { |
135 |
$color = 'yellow'; |
136 |
} else { |
137 |
$color = 'white'; |
138 |
} |
139 |
|
140 |
$buf = array(); |
141 |
//print "<hr/><b><font color=\"red\">ERROR:</font></b><br/>"; |
142 |
array_push($buf, "<div style=\"background:$color; margin:4px; border:1px black groove; padding:2px;\"><b><font color=\"red\">Event:</font></b> [$code]<br/>"); |
143 |
|
144 |
// 1. dump of error object |
145 |
if (is_array($error)) { |
146 |
foreach ($output_order as $key) { |
147 |
array_push($buf, "<b>$key:</b> $error[$key]<br/>"); |
148 |
} |
149 |
} |
150 |
// 2. additional payload |
151 |
if (is_array($payload)) { |
152 |
array_push($buf, join('<br/>', $payload) ); |
153 |
} |
154 |
|
155 |
array_push($buf, "</div><br/>\n"); |
156 |
$out = join("\n", $buf); |
157 |
|
158 |
Tracer::add($out); |
159 |
|
160 |
return $out; |
161 |
|
162 |
} |
163 |
|
164 |
|
165 |
} |
166 |
|
167 |
?> |