DEBUG_LEVEL, 'msgs' => array(), 'last_handler' => set_error_handler('handleError'), 'error_reporting' => DEBUG_ERROR_REPORTING, 'log_file' => BASE_PATH.'/tmp/log/debug.log', ); function debugDisableNotices() { global $_DEBUG; $_DEBUG['last_handler'] = set_error_handler('handleError', DEBUG_ERROR_REPORTING ^ E_NOTICE); error_reporting(DEBUG_ERROR_REPORTING ^ E_NOTICE); } function debugEnableNotices() { global $_DEBUG; $_DEBUG['last_handler'] = set_error_handler('handleError', DEBUG_ERROR_REPORTING); error_reporting(DEBUG_ERROR_REPORTING); } function handleError($errno, $errmsg, $filename, $linenum, $vars) { global $_DEBUG; $debug_msg = "[$errno] $errmsg
In line $linenum of $filename.\n"; switch ($errno) { case E_ERROR: $debug_msg = "Fatal error: $debug_msg"; break; case E_WARNING: $debug_msg = "Warning: $debug_msg"; break; case E_NOTICE: $debug_msg = "Notice: $debug_msg"; break; case E_USER_ERROR: $debug_msg = "User error: $debug_msg"; break; case E_USER_WARNING: $debug_msg = "User warning: $debug_msg"; break; case E_USER_NOTICE: $debug_msg = "User notice: $debug_msg"; break; } if ($errno & $_DEBUG['error_reporting']) debugLog($debug_msg); } function debugLog($msg) { if (!defined('DEBUG') || !DEBUG){ return false; } global $_DEBUG; $msg_date = date("Y-m-d H:i:s"); if ($_DEBUG['level'] & D_ECHO) { print("$msg_date: $msg
"); } if ($_DEBUG['level'] & D_VAR) { $_DEBUG['msgs'][] = "$msg_date: $msg"; } return true; } function varDump($var, $name = "", $funct = "") { $dump = ""; if ($name) { $dump .= "$name:
"; } $funct = $funct ? $funct : (is_scalar($var) || is_null($var) ? 'var_dump' : 'print_r'); ob_start(); print("
");
    $funct($var);
    print("
"); $dump .= ob_get_contents(); ob_end_clean(); return $dump; } function dump($var, $name = "", $method = D_VAR) { return $name ? debugLog(varDump($var, $name), $method) : debugLog(varDump($var), $method); } function vdie() { $vars = func_get_args(); foreach ($vars as $var) print(varDump($var)); exit(); } function get_micro_time() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function start_timer($name) { global $TIMER; $TIMER[$name]['start'] = get_micro_time(); } function finish_timer($name) { global $TIMER; $TIMER[$name]['end'] = get_micro_time(); $TIMER[$name]['total'] += $TIMER[$name]['end'] - $TIMER[$name]['start']; if (DEBUG) debugLog("$name: {$TIMER[$name]['total']}"); } function log_msg($msg, $tabs = 0) { global $_DEBUG; $log_file = fopen($_DEBUG['log_file'], 'a'); $log_msg = date('Y/m/d H:i:s - '); $log_msg .= str_repeat("\t", $tabs); $log_msg .= "$msg\n"; fflush($log_file); fputs($log_file, $log_msg); fflush($log_file); fclose($log_file); } ?>