ThinkPHP错误日志记录
2023-03-29 23:03:03
150
{{single.collect_count}}

最近在使用Think PHP3.2,  发现设置APP_DEBUG=false,日志信息记录不全,类找不到,或者方法不存在等致命错误信息都没有记录。百度了一下, 发现其他人也有这样的问题, 时间还是2014年的。全盘搜索register_shutdown_function,错误处理函数register_shutdown_function('Think\Think::fatalError');源码如下:

// 致命错误捕获static public function fatalError() {Log::save();if ($e = error_get_last()) {switch($e['type']){case E_ERROR:case E_PARSE:case E_CORE_ERROR:case E_COMPILE_ERROR:case E_USER_ERROR:ob_end_clean();self::halt($e);break;}}}

/** * 错误输出 * @param mixed $error 错误 * @return void */static public function halt($error) {$e = array();if (APP_DEBUG || IS_CLI) {//调试模式下输出错误信息if (!is_array($error)) {$trace= debug_backtrace();$e['message'] = $error;$e['file']= $trace[0]['file'];$e['line']= $trace[0]['line'];ob_start();debug_print_backtrace();$e['trace'] = ob_get_clean();} else {$e= $error;}if(IS_CLI){exit(iconv('UTF-8','gbk',$e['message']).PHP_EOL.'FILE: '.$e['file'].'('.$e['line'].')'.PHP_EOL.$e['trace']);}} else {//否则定向到错误页面$error_page = C('ERROR_PAGE');if (!empty($error_page)) {redirect($error_page);} else {$message= is_array($error) ? $error['message'] : $error;$e['message'] = C('SHOW_ERROR_MSG')? $message : C('ERROR_MESSAGE');}}// 包含异常页面模板$exceptionFile =C('TMPL_EXCEPTION_FILE',null,THINK_PATH.'Tpl/think_exception.tpl');include $exceptionFile;exit;}

在debug=true,或者cli模式下会把错误输出到页面, debug=false时, 又判断了SHOW_ERROR_MSG的状态, 为true又显示错误信息到页面, 没感觉出其用意。最后就是没有写入日志,不科学啊!!!出了错就只有靠猜了!!!


回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}