application
-config.php
中找到
'log' => [ // 日志记录方式,内置 file socket 支持扩展 'type' => 'file',将
'type' => 'file'
,改为 'type' => 'test'
,
private function recordErrorLog(Exception $e) { Log::init([ 'type' => 'File', 'path' => LOG_PATH, 'level' => ['error'] ]); Log::record($e->getMessage(),'error'); } |
$this->code = 500; $this->msg = '服务器内部错误'; $this->errorCode = 999; |
$this->recordErrorLog($e); |
throw new Exception('内部错误')
; 便是我们往日志文件中抛入的错误
<?php namespace app\api\validate; use think\Exception; use think\Validate; class BaseValidate extends Validate { public function goCheck() { $request = input('param.'); $result = $this->check($request); if(!$result){ throw new Exception('内部错误'); }else{ return true; } } } |
{"msg":"Banner不存在","error_code":40000,"request_url":""}
{"msg":"服务器内部错误","error_code":999,"request_url":""}在上面,
Banner不存在
这个错误将不被记录,只有服务器内部错误才被记录runtime
-log中,但我们可以改成自己需要的public
-index.php
的
'max_files' => 30则日志文件最多只会保留30个,超过会自动清理较早的日志文件,避免日志文件长期写入占满磁盘空间。
log
常规日志,用于记录日志error
错误,一般会导致程序的终止notice
警告,程序可以运行但是还不够完美的错误info
信息,程序输出信息debug
调试,用于调试信息sql
SQL语句,用于SQL记录,只在数据库的调试模式开启时有效
创始人微信
路漫漫其修远兮 吾将上下而求索添加创始人微信,一起交流心得
时间:2017年06月12日
时间:2019年04月10日
时间:2017年01月13日
时间:2017年04月09日
时间:2017年01月09日
评论