Skip to content

Commit

Permalink
fix: LoggerBehavior beforeSend
Browse files Browse the repository at this point in the history
  • Loading branch information
forecho committed Jul 31, 2020
1 parent 808f56e commit 0bf92fa
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions core/behaviors/LoggerBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ public function events()
public function beforeSend($event)
{
$response = $event->sender;
$request = \Yii::$app->request;
$requestId = Yii::$app->requestId->id;
$code = ArrayHelper::getValue($response->data, 'code');
$message = [
'request_id' => $requestId,
'type' => $code === 0 ? 'response_data_success' : 'response_data_error',
'header' => Json::encode($request->headers),
'params' => $request->bodyParams,
'url' => $request->absoluteUrl,
'response' => Json::encode($response->data)
];
$response->data = ['request_id' => $requestId] + $response->data;
$code === 0 ? Yii::info($message, 'request') : Yii::error($message, 'request');
if ($response->format != 'html') {
$request = \Yii::$app->request;
$requestId = Yii::$app->requestId->id;
$code = ArrayHelper::getValue($response->data, 'code');
$message = [
'request_id' => $requestId,
'type' => $code === 0 ? 'response_data_success' : 'response_data_error',
'header' => Json::encode($request->headers),
'params' => $request->bodyParams,
'url' => $request->absoluteUrl,
'response' => Json::encode($response->data)
];
$response->data = ['request_id' => $requestId] + $response->data;
$code === 0 ? Yii::info($message, 'request') : Yii::error($message, 'request');
}
}

public function beforeAction()
Expand Down

0 comments on commit 0bf92fa

Please sign in to comment.