errorCode=$errorCode; $this->friendmsg=$friendmsg; $this->catalog=$catalog; if (is_array($friendmsg)) $friendmsg = @json_encode($friendmsg); parent::__construct($friendmsg, $code, $previous); } } function eeglobal_deferrorhandler($level,$message,$file='',$line=0){ if(error_reporting() & $level){ $exp = new GeneralException('DEFAULT_ERROR_HANDLER',EEGLOBAL_DEFAULT_USERERRORMSG.$message, EEGLOBAL_DEFAULT_CATALOGNAME,0,null,$file,$line); eeglobal_exception_handler($exp,false); } return true;/* Don't execute PHP internal error handler */ } function eeglobal_shutdownhandler(){ $err=error_get_last(); if ($err) { $exp = new GeneralException('DEFAULT_SHUTDOWN_HANDLER',EEGLOBAL_DEFAULT_USERERRORMSG.$err['message'], EEGLOBAL_DEFAULT_CATALOGNAME,0,null,$err['file'],$err['line']); eeglobal_exception_handler($exp,false); } } function eeglobal_defexceptionhandler($ex){ eeglobal_exception_handler($ex,false); } function eeglobal_exception_handler($ex,$ajaxOutput){ try{ if(!is_object($ex)) return; $exstackinfo = array(); $errorCode = "General"; $friendmsg = EEGLOBAL_DEFAULT_USERERRORMSG; $catalog = EEGLOBAL_DEFAULT_CATALOGNAME; do { $clsname=get_class($ex); $errorCode = ($clsname=='GeneralException'?$ex->errorCode : $errorCode); $friendmsg = ($clsname=='GeneralException'?$ex->friendmsg : $friendmsg); $catalog = ($clsname=='GeneralException'?$ex->catalog : $catalog); $logcontent=$ex->getMessage()."\r\n"; $expfile=$ex->getFile(); $expline=$ex->getLine(); $expcode=$ex->getCode(); $logcontent.=" 异常发生在文件:[{$expfile}]的[{$expline}]行 code[{$expcode}] !\r\n"; $exptrace=str_replace("\n", "\r\n ", $ex->getTraceAsString()); $logcontent.=" 异常堆栈上下文:\r\n"; $logcontent.=" {$exptrace}"; array_push($exstackinfo,$logcontent); } while($ex = $ex->getPrevious()); $strExAll=join("\r\n",$exstackinfo); eeglobal_log_handler_core($catalog,"error",$strExAll,true); if($ajaxOutput){ $ajaxRes = new AjaxResult; $ajaxRes->ErrCode=$errorCode; $ajaxRes->ErrMsg=$friendmsg; ob_clean(); ob_start(); header('Content-Type:application/json;charset=UTF-8'); echo @json_encode($ajaxRes); exit; } }catch(Throwable $ex){ } } function eeglobal_log_handler_core($catalog,$loglevel,$logcontent,$hasContext=false){ if($hasContext){ $_GP = array(); $_GP = array_merge($_REQUEST, $_COOKIE, $_SERVER, $_GP); $context = array(); foreach ($_GP as $key => $value) { if(is_array($value)){ $value=implode($value); } array_push($context,"\t[$key]=$value"); } $strContext="\r\n[上下文相关信息]:\r\n".join("\r\n",$context); $logcontent .= $strContext; } $logPath=EEGLOBAL_LOG_PATH . date("YmdH")."_".$catalog.".log"; error_log(date("H:i:s"). " [{$loglevel}]: $logcontent \r\n\r\n", 3, $logPath); } function eeglobal_log_handler($catalog,$loglevel,$logcontent,$hasContext=false){ eeglobal_log_handler_core($catalog,$loglevel,$logcontent,$hasContext); }