14 |
* $Id$ |
* $Id$ |
15 |
* |
* |
16 |
* $Log$ |
* $Log$ |
17 |
|
* Revision 1.4 2003/04/08 17:57:29 joko |
18 |
|
* minor fix: increased width of debug-box |
19 |
|
* |
20 |
|
* Revision 1.3 2003/04/06 04:25:41 joko |
21 |
|
* + function get_last |
22 |
|
* + function out_plain_last10 |
23 |
|
* |
24 |
|
* Revision 1.2 2003/04/05 21:19:38 joko |
25 |
|
* + function event |
26 |
|
* - function warn |
27 |
|
* - function info |
28 |
|
* |
29 |
* Revision 1.1 2003/04/04 02:17:22 joko |
* Revision 1.1 2003/04/04 02:17:22 joko |
30 |
* initial commit |
* initial commit |
31 |
* |
* |
50 |
*/ |
*/ |
51 |
|
|
52 |
|
|
53 |
Exporter::export_symbols('Tracer', array('warn', 'info')); |
// lowlevel (just calls 'Dumper') |
54 |
Exporter::export_symbol('Tracer', array('add' => 'trace')); |
Exporter::export_symbol('Tracer', array('add' => 'trace')); |
55 |
|
// highlevel (draws colored boxes) |
56 |
|
//Exporter::export_symbols('Tracer', array('warn', 'info')); |
57 |
|
|
58 |
|
|
59 |
class Tracer { |
class Tracer { |
60 |
|
|
61 |
function warn() { |
function get_last($x) { |
62 |
$parts = func_get_args(); |
global $_TRACE; |
63 |
user_error ( join('<br/>', $parts), E_USER_WARNING ); |
return array_slice($_TRACE, -$x); |
|
} |
|
|
|
|
|
function info() { |
|
|
$parts = func_get_args(); |
|
|
//print "info: " . Dumper($parts); |
|
|
errors::add_trace($parts); |
|
64 |
} |
} |
65 |
|
|
66 |
function box($dom_id = 'errorbox') { |
function box($dom_id = 'errorbox') { |
|
global $_TRACE; |
|
67 |
|
|
68 |
// FIXME: ie/mozilla? |
// FIXME: ie/mozilla? |
69 |
$errblock = html_div(); |
$errblock = html_div(); |
70 |
$errblock->set_id($dom_id); |
$errblock->set_id($dom_id); |
71 |
$errblock->set_style('display:none;'); |
|
72 |
|
// V1 |
73 |
|
//$errblock->set_style('display:none;'); |
74 |
|
// V2 |
75 |
|
//$errblock->set_style('visibility:hidden; float:none; left: 50%; position:absolute; z-index:1;'); |
76 |
|
$errblock->set_style('visibility:hidden; position:absolute; z-index:1; left:5px; background: #eeeeee; margin-top:30px; padding:5px; border:1px solid black;'); |
77 |
|
|
78 |
|
//$errblock->add( html_br(), html_br() ); |
79 |
$errblock->add( html_b( "Events: (# " . sizeof($_TRACE) . ")" ) ); |
$errblock->add( html_b( "Events: (# " . sizeof($_TRACE) . ")" ) ); |
80 |
|
|
81 |
// FIXME: just use the last 50 entries... |
// FIXME: just use the last 50 entries... |
82 |
$last50 = array_slice($_TRACE, -50); |
$lastX = Tracer::get_last(50); |
83 |
foreach ($last50 as $error) { |
foreach ($lastX as $error) { |
84 |
$errblock->add( $error ); |
$errblock->add( $error ); |
85 |
} |
} |
86 |
//$errblock->add($_TRACE); |
//$errblock->add($_TRACE); |
87 |
|
|
88 |
return $errblock; |
return $errblock; |
89 |
} |
} |
90 |
|
|
91 |
|
function out_plain_last10($dom_id) { |
92 |
|
$errblock = html_div(); |
93 |
|
$errblock->set_id($dom_id); |
94 |
|
$errblock->set_style('display:none;'); |
95 |
|
$lastX = Tracer::get_last(10); |
96 |
|
$errblock->add( join("\n---\n", $lastX) ); |
97 |
|
return $errblock; |
98 |
|
} |
99 |
|
|
100 |
function add($payload = null) { |
function add($payload = null) { |
101 |
global $_TRACE; |
global $_TRACE; |
111 |
|
|
112 |
} |
} |
113 |
|
|
114 |
|
function event($args = array()) { |
115 |
|
|
116 |
|
//print "event!!!<br/>"; |
117 |
|
//print Dumper($args); |
118 |
|
|
119 |
|
$type = $args[type]; |
120 |
|
$code = $args[code]; |
121 |
|
$error = $args[error]; |
122 |
|
$payload = $args[payload]; |
123 |
|
|
124 |
|
switch ($type) { |
125 |
|
case 'full': |
126 |
|
$output_order = array( 'message', 'component', 'file', 'line', 'level' ); |
127 |
|
break; |
128 |
|
case 'medium': |
129 |
|
$output_order = array( 'message', 'level', 'file', 'line' ); |
130 |
|
break; |
131 |
|
default: |
132 |
|
$output_order = array( 'message', 'level' ); |
133 |
|
break; |
134 |
|
} |
135 |
|
|
136 |
|
// dispatch color by level |
137 |
|
if ($code <= 8) { |
138 |
|
$color = '#eeeeee'; |
139 |
|
} elseif ($code == 512) { |
140 |
|
$color = 'orange'; |
141 |
|
} elseif ($code == 1024) { |
142 |
|
$color = 'yellow'; |
143 |
|
} else { |
144 |
|
$color = 'white'; |
145 |
|
} |
146 |
|
|
147 |
|
$buf = array(); |
148 |
|
//print "<hr/><b><font color=\"red\">ERROR:</font></b><br/>"; |
149 |
|
array_push($buf, "<div style=\"width:640px;background:$color; margin:4px; border:1px black groove; padding:2px;\"><b><font color=\"red\">Event:</font></b> [$code]<br/>"); |
150 |
|
|
151 |
|
// 1. dump of error object |
152 |
|
if (is_array($error)) { |
153 |
|
foreach ($output_order as $key) { |
154 |
|
array_push($buf, "<b>$key:</b> $error[$key]<br/>"); |
155 |
|
} |
156 |
|
} |
157 |
|
// 2. additional payload |
158 |
|
if (is_array($payload)) { |
159 |
|
array_push($buf, join('<br/>', $payload) ); |
160 |
|
} |
161 |
|
|
162 |
|
array_push($buf, "</div><br/>\n"); |
163 |
|
$out = join("\n", $buf); |
164 |
|
|
165 |
|
Tracer::add($out); |
166 |
|
|
167 |
|
return $out; |
168 |
|
|
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
} |
} |
173 |
|
|
174 |
?> |
?> |