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