--- nfo/php/libs/org.netfrag.app/Tracer.php 2003/04/04 02:17:22 1.1 +++ nfo/php/libs/org.netfrag.app/Tracer.php 2003/04/06 04:25:41 1.3 @@ -11,9 +11,18 @@ */ /** - * $Id: Tracer.php,v 1.1 2003/04/04 02:17:22 joko Exp $ + * $Id: Tracer.php,v 1.3 2003/04/06 04:25:41 joko Exp $ * * $Log: Tracer.php,v $ + * Revision 1.3 2003/04/06 04:25:41 joko + * + function get_last + * + function out_plain_last10 + * + * Revision 1.2 2003/04/05 21:19:38 joko + * + function event + * - function warn + * - function info + * * Revision 1.1 2003/04/04 02:17:22 joko * initial commit * @@ -38,42 +47,52 @@ */ -Exporter::export_symbols('Tracer', array('warn', 'info')); +// lowlevel (just calls 'Dumper') Exporter::export_symbol('Tracer', array('add' => 'trace')); +// highlevel (draws colored boxes) +//Exporter::export_symbols('Tracer', array('warn', 'info')); class Tracer { - function warn() { - $parts = func_get_args(); - user_error ( join('
', $parts), E_USER_WARNING ); - } - - function info() { - $parts = func_get_args(); - //print "info: " . Dumper($parts); - errors::add_trace($parts); + function get_last($x) { + global $_TRACE; + return array_slice($_TRACE, -$x); } function box($dom_id = 'errorbox') { - global $_TRACE; // FIXME: ie/mozilla? $errblock = html_div(); $errblock->set_id($dom_id); - $errblock->set_style('display:none;'); + + // V1 + //$errblock->set_style('display:none;'); + // V2 + //$errblock->set_style('visibility:hidden; float:none; left: 50%; position:absolute; z-index:1;'); + $errblock->set_style('visibility:hidden; position:absolute; z-index:1; left:5px; background: #eeeeee; margin-top:30px; padding:5px; border:1px solid black;'); + //$errblock->add( html_br(), html_br() ); $errblock->add( html_b( "Events: (# " . sizeof($_TRACE) . ")" ) ); // FIXME: just use the last 50 entries... - $last50 = array_slice($_TRACE, -50); - foreach ($last50 as $error) { + $lastX = Tracer::get_last(50); + foreach ($lastX as $error) { $errblock->add( $error ); } //$errblock->add($_TRACE); return $errblock; } + + function out_plain_last10($dom_id) { + $errblock = html_div(); + $errblock->set_id($dom_id); + $errblock->set_style('display:none;'); + $lastX = Tracer::get_last(10); + $errblock->add( join("\n---\n", $lastX) ); + return $errblock; + } function add($payload = null) { global $_TRACE; @@ -89,6 +108,64 @@ } + function event($args = array()) { + + //print "event!!!
"; + //print Dumper($args); + + $type = $args[type]; + $code = $args[code]; + $error = $args[error]; + $payload = $args[payload]; + + switch ($type) { + case 'full': + $output_order = array( 'message', 'component', 'file', 'line', 'level' ); + break; + case 'medium': + $output_order = array( 'message', 'level', 'file', 'line' ); + break; + default: + $output_order = array( 'message', 'level' ); + break; + } + + // dispatch color by level + if ($code <= 8) { + $color = '#eeeeee'; + } elseif ($code == 512) { + $color = 'orange'; + } elseif ($code == 1024) { + $color = 'yellow'; + } else { + $color = 'white'; + } + + $buf = array(); + //print "
ERROR:
"; + array_push($buf, "
Event: [$code]
"); + + // 1. dump of error object + if (is_array($error)) { + foreach ($output_order as $key) { + array_push($buf, "$key: $error[$key]
"); + } + } + // 2. additional payload + if (is_array($payload)) { + array_push($buf, join('
', $payload) ); + } + + array_push($buf, "

\n"); + $out = join("\n", $buf); + + Tracer::add($out); + + return $out; + + } + + } ?> \ No newline at end of file