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