Changeset 11146 for freepbx

Show
Ignore:
Timestamp:
01/27/11 02:58:32 (2 years ago)
Author:
p_lindheimer
Message:

make the backtrace of die_freepbx a little less verbose and presentable (though html version coudld be improved), and add freebpx_conf option to add the full back_trace() detail

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.9/amp_conf/htdocs/admin/libraries/utility.functions.php

    r11145 r11146  
    2323  $bt = debug_backtrace(); 
    2424 
    25   if ($bt[1]['function'] == 'out') { 
     25  if ($bt[1]['function'] == 'out' || $bt[1]['function'] == 'die_freepbx') { 
    2626    $file_full = $bt[1]['file']; 
    2727    $line = $bt[1]['line']; 
     
    8282 
    8383function die_freepbx($text, $extended_text="", $type="FATAL") { 
    84   $trace = print_r(debug_backtrace(),true); 
     84  global $amp_conf; 
     85 
     86  $bt = debug_backtrace(); 
     87  freepbx_log(FPBX_LOG_FATAL, "die_freepbx(): ".$text); 
     88 
    8589  if (isset($_SERVER['REQUEST_METHOD'])) { 
    8690    // running in webserver 
    87     echo "<h1>".$type." ERROR</h1>\n"; 
    88     echo "<h3>".$text."</h3>\n"; 
     91    $trace = "<h1>".$type." ERROR</h1>\n"; 
     92    $trace .= "<h3>".$text."</h3>\n"; 
    8993    if (!empty($extended_text)) { 
    90       echo "<p>".$extended_text."</p>\n"; 
     94      $trace .= "<p>".$extended_text."</p>\n"; 
    9195    } 
    92     echo "<h4>"._("Trace Back")."</h4>"; 
    93     echo "<pre>$trace</pre>"; 
     96    $trace .= "<h4>"._("Trace Back")."</h4>"; 
     97 
     98    $main_fmt = "%s:%s %s()<br />\n"; 
     99    $arg_fmt = "&nbsp;&nbsp;[%s]: %s<br />\n"; 
     100    $separator = "<br />\n"; 
     101    $tail = "<br />\n"; 
     102    $f = 'htmlspecialchars'; 
    94103  } else { 
    95104    // CLI 
    96     echo "[$type] ".$text." ".$extended_text."\n"; 
    97     echo "Trace Back:\n"; 
    98     echo $trace; 
    99   } 
    100  
    101   // always ensure we exit at this point 
     105    $trace =  "[$type] ".$text." ".$extended_text."\n\n"; 
     106    $trace .= "Trace Back:\n\n"; 
     107 
     108    $main_fmt = "%s:%s %s()\n"; 
     109    $arg_fmt = " [%s]: %s\n"; 
     110    $separator = "\n"; 
     111    $tail = ""; 
     112    $f = 'trim'; 
     113  } 
     114 
     115  foreach ($bt as $l) { 
     116    $cl = isset($l['class']) ? $f($l['class']) : ''; 
     117    $ty = isset($l['type']) ? $f($l['type']) : ''; 
     118    $func = $f($cl . $ty . $l['function']); 
     119    $trace .= sprintf($main_fmt, $l['file'], $l['line'], $func); 
     120    if (isset($l['args'])) foreach ($l['args'] as $i => $a) { 
     121      $trace .= sprintf($arg_fmt, $i, $f($a)); 
     122    } 
     123    $trace .= $separator; 
     124  } 
     125  echo $trace . $tail; 
     126 
     127  if ($amp_conf['DIE_FREEPBX_VERBOSE']) { 
     128    $trace = print_r($bt,true); 
     129    if (isset($_SERVER['REQUEST_METHOD'])) { 
     130      echo '<pre>' .$trace. '</pre>'; 
     131    } else { 
     132      echo $trace; 
     133    } 
     134  } 
     135 
     136  // Now die! 
    102137  exit(1); 
    103138} 
  • freepbx/branches/2.9/libfreepbx.install.php

    r11128 r11146  
    11971197  $freepbx_conf->define_conf_setting('FPBXDBUGDISABLE',$set); 
    11981198 
     1199  // DIE_FREEPBX_VERBOSE 
     1200  $set['value'] = false; 
     1201  $set['options'] = ''; 
     1202  $set['name'] = 'Provide Verbose Tracebacks'; 
     1203  $set['description'] = 'Provides a very verbose traceback when die_freepbx() is called including extensive object details if present in the traceback.'; 
     1204  $set['emptyok'] = 0; 
     1205  $set['readonly'] = 0; 
     1206  $set['type'] = CONF_TYPE_BOOL; 
     1207  $freepbx_conf->define_conf_setting('DIE_FREEPBX_VERBOSE',$set); 
     1208 
     1209 
     1210 
    11991211  // DEVEL 
    12001212  $set['value'] = false;