app\Providers\AppServiceProvider.php
在boot方法添加处理代码
\DB::listen(function($sql, $bindings, $time){ $file = date('Ymd').'_sql.log'; $path = storage_path('logs/'.$file); $str = date('H:i:s').' '.$time.' '.$sql."\n"; file_put_contents($path, $str, FILE_APPEND); });
时间为秒
接口项目将异常以json格式返回
app\Exceptions\Handler.php
public function render($request, Exception $e) { if ($e instanceof ModelNotFoundException) { $e = new NotFoundHttpException($e->getMessage(), $e); } $error = $e->getMessage(); if(!$error) $error = '404'; $type = env('JSONERROR','enable'); if($type == 'disable'){ return parent::render($request, $e); }else{ return response()->json(array('msg'=>$error,'status'=>0)); } }