author:咔咔
wechat:fangkangfk
在控制器创建exception控制器,并重写render方法
<?php namespace app\admin\controller; use think\Log; use Exception as Exceptionthink; use think\exception\Handle; class Exception extends Handle { public function render(Exceptionthink $e) { $errorMessage = $e->getMessage(); $errorFile = $e->getFile(); $errorLine = $e->getLine(); $errorTime = date('Y-m-d H-i-s',time()); $data = [ 'Time' => $errorTime, 'Message' => $errorMessage, 'File' => $errorFile, 'Line' => $errorLine ]; Log::init([ 'type' => 'file', 'path' => ROOT_PATH . 'error_log/', 'apart_level' => ['error'], 'max_files' => 7 ]); Log::write($data); return redirect('admin/error/index'); } }
然后在配置文件配置,这里是单独给后台做的异常,所以没有在公共配置文件写。