Browse Source

日志优化

master
weigang 5 years ago
parent
commit
e485fc2deb
  1. 6
      app/Controller/v3/WithdrawController.php
  2. 13
      app/Exception/ErrorCodeException.php
  3. 2
      app/Exception/Handler/ErrorCodeExceptionHandler.php

6
app/Controller/v3/WithdrawController.php

@ -138,7 +138,11 @@ class WithdrawController extends BaseController
->where(['source_id' => $store->user_id, 'user_type' => UserType::STORE])
->first();
if ($money > $balance->balance) {
throw new ErrorCodeException(ErrorCode::STORE_WITHDRAW_INSUFFICIENT_BALANCE, '', ['message' => '商户提现余额不足','data' => ['money' => $money, 'balance' => $balance->balance]]);
throw new ErrorCodeException(
ErrorCode::STORE_WITHDRAW_INSUFFICIENT_BALANCE,
'',
['message' => 'store withdraw balance not enough','data' => ['user_id' => $userId, 'store_id' => $storeId, 'money' => $money, 'balance' => $balance->balance]]
);
}
Db::beginTransaction();

13
app/Exception/ErrorCodeException.php

@ -29,15 +29,16 @@ class ErrorCodeException extends ServerException
public function __construct(int $code = 0, string $message = null, $logData=[], Throwable $previous = null)
{
if (!empty($logData)) {
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['logData' => json_encode($logData)]);
}
if (is_null($message)) {
$message = ErrorCode::getMessage($code);
} else {
$message = ErrorCode::getMessage($code) . '_' . $message;
$message = ErrorCode::getMessage($code) . ' ' . $message;
}
if (!empty($logData)) {
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION_LOG_DATA, ['message' => $message, 'logData' => json_encode($logData)]);
} else {
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION, ['message' => $message]);
}
parent::__construct($message, $code, $previous);

2
app/Exception/Handler/ErrorCodeExceptionHandler.php

@ -44,8 +44,6 @@ class ErrorCodeExceptionHandler extends ExceptionHandler
"message" => $throwable->getMessage()
];
$this->log->event(LogLabel::ERROR_CODE_EXCEPTION, ['error_exception_msg' => $content['message']]);
return $response->withHeader('Content-Type', 'application/json')
->withStatus(200)
->withBody(new SwooleStream(json_encode($content)));

Loading…
Cancel
Save