| 278 | | function dbug_write($txt,$check=''){ |
|---|
| 279 | | global $amp_conf; |
|---|
| 280 | | |
|---|
| 281 | | // dbug can be used prior to bootstrapping and initialization, so we set |
|---|
| 282 | | // it if not defined here to a default. |
|---|
| 283 | | // |
|---|
| 284 | | if (!isset($amp_conf['FPBXDBUGFILE'])) { |
|---|
| 285 | | $amp_conf['FPBXDBUGFILE'] = '/tmp/freepbx_debug.log'; |
|---|
| 286 | | } |
|---|
| 287 | | $append=false; |
|---|
| 288 | | //optionaly ensure that dbug file is smaller than $max_size |
|---|
| 289 | | if($check){ |
|---|
| 290 | | $max_size = 52428800;//hardcoded to 50MB. is that bad? not enough? |
|---|
| 291 | | $size = filesize($amp_conf['FPBXDBUGFILE']); |
|---|
| 292 | | $append = (($size > $max_size) ? false : true ); |
|---|
| 293 | | } |
|---|
| 294 | | if ($append) { |
|---|
| 295 | | file_put_contents($amp_conf['FPBXDBUGFILE'], $txt); |
|---|
| 296 | | } else { |
|---|
| 297 | | file_put_contents($amp_conf['FPBXDBUGFILE'], $txt, FILE_APPEND); |
|---|
| 298 | | } |
|---|
| 299 | | |
|---|
| 300 | | } |
|---|
| 301 | | |
|---|
| 302 | | |
|---|
| 562 | | } |
|---|
| 563 | | |
|---|
| 564 | | |
|---|
| 565 | | //http://php.net/manual/en/function.set-error-handler.php |
|---|
| 566 | | function freepbx_error_handler($errno, $errstr, $errfile, $errline, $errcontext) { |
|---|
| 567 | | global $amp_conf; |
|---|
| 568 | | |
|---|
| 569 | | //for pre 5.2 |
|---|
| 570 | | if (!defined('E_RECOVERABLE_ERROR')) { |
|---|
| 571 | | define('E_RECOVERABLE_ERROR', ''); |
|---|
| 572 | | } |
|---|
| 573 | | $errortype = array ( |
|---|
| 574 | | E_ERROR => 'ERROR', |
|---|
| 575 | | E_WARNING => 'WARNING', |
|---|
| 576 | | E_PARSE => 'PARSE_ERROR', |
|---|
| 577 | | E_NOTICE => 'NOTICE', |
|---|
| 578 | | E_CORE_ERROR => 'CORE_ERROR', |
|---|
| 579 | | E_CORE_WARNING => 'CORE_WARNING', |
|---|
| 580 | | E_COMPILE_ERROR => 'COMPILE_ERROR', |
|---|
| 581 | | E_COMPILE_WARNING => 'COMPILE_WARNING', |
|---|
| 582 | | E_USER_ERROR => 'USER_ERROR', |
|---|
| 583 | | E_USER_WARNING => 'USER_WARNING', |
|---|
| 584 | | E_USER_NOTICE => 'USER_NOTICE', |
|---|
| 585 | | E_STRICT => 'RUNTIM_NOTICE', |
|---|
| 586 | | E_RECOVERABLE_ERROR => 'CATCHABLE_FATAL_ERROR', |
|---|
| 587 | | ); |
|---|
| 588 | | |
|---|
| 589 | | if (!isset($amp_conf['PHP_ERROR_HANDLER_OUTPUT'])) { |
|---|
| 590 | | $amp_conf['PHP_ERROR_HANDLER_OUTPUT'] = 'dbug'; |
|---|
| 591 | | } |
|---|
| 592 | | |
|---|
| 593 | | switch($amp_conf['PHP_ERROR_HANDLER_OUTPUT']) { |
|---|
| 594 | | case 'freepbxlog': |
|---|
| 595 | | $txt = sprintf("%s] (%s:%s) - %s", $errortype[$errno], $errfile, $errline, $errstr); |
|---|
| 596 | | freepbx_log(FPBX_LOG_PHP,$txt); |
|---|
| 597 | | break; |
|---|
| 598 | | case 'off': |
|---|
| 599 | | break; |
|---|
| 600 | | case 'dbug': |
|---|
| 601 | | default: |
|---|
| 602 | | $txt = date("Y-M-d H:i:s") |
|---|
| 603 | | . "\t" . $errfile . ':' . $errline |
|---|
| 604 | | . "\n" |
|---|
| 605 | | . '[' . $errortype[$errno] . ']: ' |
|---|
| 606 | | . $errstr |
|---|
| 607 | | . "\n\n"; |
|---|
| 608 | | dbug_write($txt, $check=''); |
|---|
| 609 | | break; |
|---|
| 610 | | } |
|---|