自订义错误返回为什么还会记录日志?需要配置其他什么东西吗?怎么才能在这里不记录日志?
配置:
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请求返回json数据
if ($request->expectsJson()) {
return json(['code' => $this->getCode() ?: 500, 'msg' => $this->getMessage()]);
}
// 非json请求则返回一个页面
return new Response(200, [], $this->getMessage());
}
}
调用:
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);
}