/[cvs]/nfo/php/libs/org.netfrag.app/Tracer.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.app/Tracer.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Fri Apr 4 02:17:22 2003 UTC revision 1.3 by joko, Sun Apr 6 04:25:41 2003 UTC
# Line 14  Line 14 
14   * $Id$   * $Id$
15   *   *
16   * $Log$   * $Log$
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   * Revision 1.1  2003/04/04 02:17:22  joko
27   * initial commit   * initial commit
28   *   *
# Line 38  Line 47 
47   */   */
48    
49    
50  Exporter::export_symbols('Tracer', array('warn', 'info'));  // lowlevel (just calls 'Dumper')
51  Exporter::export_symbol('Tracer', array('add' => 'trace'));  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 {  class Tracer {
57        
58    function warn() {    function get_last($x) {
59      $parts = func_get_args();      global $_TRACE;
60      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);  
61    }    }
62    
63    function box($dom_id = 'errorbox') {    function box($dom_id = 'errorbox') {
     global $_TRACE;  
64    
65      // FIXME: ie/mozilla?      // FIXME: ie/mozilla?
66      $errblock = html_div();      $errblock = html_div();
67      $errblock->set_id($dom_id);      $errblock->set_id($dom_id);
68      $errblock->set_style('display:none;');      
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) . ")" ) );      $errblock->add( html_b( "Events: (# " . sizeof($_TRACE) . ")" ) );
77    
78      // FIXME: just use the last 50 entries...      // FIXME: just use the last 50 entries...
79      $last50 = array_slice($_TRACE, -50);      $lastX = Tracer::get_last(50);
80      foreach ($last50 as $error) {      foreach ($lastX as $error) {
81        $errblock->add( $error );        $errblock->add( $error );
82      }      }
83      //$errblock->add($_TRACE);      //$errblock->add($_TRACE);
84            
85      return $errblock;      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) {    function add($payload = null) {
98      global $_TRACE;      global $_TRACE;
# Line 89  class Tracer { Line 108  class Tracer {
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=\"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  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed