接口新增记录日志
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\support;
|
||||
|
||||
use support\Log;
|
||||
use support\Response;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
|
||||
@@ -93,6 +94,20 @@ abstract class BaseController
|
||||
$statusCode = $header['statusCode'] ?? 200;
|
||||
unset($header['statusCode']);
|
||||
|
||||
if ($code !== 1) {
|
||||
$req = $this->request;
|
||||
$method = $req ? $req->method() : '';
|
||||
$path = $req ? trim($req->path(), '/') : '';
|
||||
$ip = $req ? strval($req->getRealIp()) : '';
|
||||
$msgForLog = $msg;
|
||||
if (function_exists('mb_strlen') && function_exists('mb_substr') && mb_strlen($msgForLog) > 2000) {
|
||||
$msgForLog = mb_substr($msgForLog, 0, 2000) . '...';
|
||||
} elseif (strlen($msgForLog) > 2000) {
|
||||
$msgForLog = substr($msgForLog, 0, 2000) . '...';
|
||||
}
|
||||
Log::error('[API] ' . $method . ' /' . $path . ' | business_code=' . strval($code) . ' http=' . strval($statusCode) . ' ip=' . $ip . ' msg=' . $msgForLog);
|
||||
}
|
||||
|
||||
$headers = array_merge(['Content-Type' => 'application/json'], $header);
|
||||
$options = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
|
||||
if (defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
|
||||
|
||||
Reference in New Issue
Block a user