自訂義錯(cuò)誤返回為什么還會(huì)記錄日志?需要配置其他什么東西嗎?怎么才能在這里不記錄日志?
配置:
return [
'default' => [
'handlers' => [
[
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
runtime_path() . '/logs/webman.log',
7, //$maxFiles
Monolog\Logger::DEBUG,
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class,
'constructor' => [null, 'Y-m-d H:i:s', true],
],
]
],
],
];
app\common\support\EruException.php
<?php
declare (strict_types = 1);
namespace app\common\support;
use support\exception\BusinessException;
use Webman\Http\Request;
use Webman\Http\Response;
class EruException extends BusinessException
{
public function render(Request $request): ?Response
{
// json請(qǐng)求返回json數(shù)據(jù)
if ($request->expectsJson()) {
return json(['code' => $this->getCode() ?: 500, 'msg' => $this->getMessage()]);
}
// 非json請(qǐng)求則返回一個(gè)頁(yè)面
return new Response(200, [], $this->getMessage());
}
}
調(diào)用:
function ResClient($msg = '查詢成功',$code = '1',$data = '',$url = '',$wait = '3',$json = false,$temp = '',$browser_code = 200){
if(!empty(request()->viewconf['app']) && request()->viewconf['app'] == 'api'){
$json = true;
}
$res = [
'code' => $code,
'msg' => $msg,
'wait' => $wait ?? '3',
'time' => time(),
'url' => $url,
'json' => $json,
'temp' => empty($temp) ? '' : $temp,
'data' => $data
];
throw new \app\common\support\EruException(json_encode($res,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES),$browser_code);
}