function dbug() { $opts = func_get_args(); //call_user_func_array('freepbx_debug',$opts); $dump = 0; //sort arguments switch (count($opts)) { case 1: $msg = $opts[0]; break; case 2: if (is_array($opts[0]) || is_object($opts[0])) { $msg = $opts[0]; $dump = $opts[1]; } else { $disc = $opts[0]; $msg = $opts[1]; } break; case 3: $disc = $opts[0]; $msg = $opts[1]; $dump = $opts[2]; break; } if ($disc) { $disc = ' \'' . $disc . '\':'; } $txt = date("Y-M-d H:i:s") . $disc . "\n"; //add timestamp dbug_write($txt, 1); if ($dump == 1) { //force output via var_dump ob_start(); var_dump($msg); $msg = ob_get_contents(); ob_end_clean(); dbug_write($msg . "\n"); } elseif (is_array($msg) || is_object($msg)) { dbug_write(print_r($msg, true) . "\n"); } else { dbug_write($msg . "\n"); } }
function freepbx_error_handler($errno, $errstr, $errfile, $errline, $errcontext) { global $amp_conf; //for pre 5.2 if (!defined('E_RECOVERABLE_ERROR')) { define('E_RECOVERABLE_ERROR', ''); } $errortype = array(E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSE_ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE_ERROR', E_CORE_WARNING => 'CORE_WARNING', E_COMPILE_ERROR => 'COMPILE_ERROR', E_COMPILE_WARNING => 'COMPILE_WARNING', E_DEPRECATED => 'DEPRECATION_WARNING', E_USER_ERROR => 'USER_ERROR', E_USER_WARNING => 'USER_WARNING', E_USER_NOTICE => 'USER_NOTICE', E_STRICT => 'RUNTIM_NOTICE', E_RECOVERABLE_ERROR => 'CATCHABLE_FATAL_ERROR'); if (!isset($amp_conf['PHP_ERROR_HANDLER_OUTPUT'])) { $amp_conf['PHP_ERROR_HANDLER_OUTPUT'] = 'dbug'; } switch ($amp_conf['PHP_ERROR_HANDLER_OUTPUT']) { case 'freepbxlog': $txt = sprintf("%s] (%s:%s) - %s", $errortype[$errno], $errfile, $errline, $errstr); freepbx_log(FPBX_LOG_PHP, $txt); break; case 'off': break; case 'dbug': default: $errormsg = isset($errortype[$errno]) ? $errortype[$errno] : 'Undefined Error'; $txt = date("Y-M-d H:i:s") . "\t" . $errfile . ':' . $errline . "\n" . '[' . $errormsg . ']: ' . $errstr . "\n\n"; dbug_write($txt, $check = ''); break; } }