From: fomichev Date: Wed, 26 Feb 2025 12:29:00 +0000 (+0300) Subject: Логирование в файл X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=de463423ef3f847b8c7b5128884af9d54f3e9426;p=erp24_rep%2Fyii-erp24%2F.git Логирование в файл --- diff --git a/erp24/.gitignore b/erp24/.gitignore index c25408fc..8943eaed 100644 --- a/erp24/.gitignore +++ b/erp24/.gitignore @@ -40,4 +40,5 @@ tests/_support/_generated /data/* /runtime/* /api2/runtime/* -/api2/json/* \ No newline at end of file +/api2/json/* +/media/notification/* \ No newline at end of file diff --git a/erp24/media/controllers/NotificationController.php b/erp24/media/controllers/NotificationController.php index b36e951d..9c5ef109 100644 --- a/erp24/media/controllers/NotificationController.php +++ b/erp24/media/controllers/NotificationController.php @@ -22,6 +22,9 @@ use yii_app\services\MarketplaceService; class NotificationController extends Controller { + const OUT_DIR = + //"/www/media/notification"; + "/var/www/erp24/media/notification"; public function actionTest() { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; @@ -66,11 +69,21 @@ class NotificationController extends Controller */ $rawBody = Yii::$app->request->getRawBody(); + file_put_contents( + self::OUT_DIR . '/notifications.json', + PHP_EOL . date('Y-m-d H:i:s') . ' ' . $rawBody, + FILE_APPEND + ); try { $data = Json::decode($rawBody); } catch (\Exception $e) { Yii::error("Ошибка декодирования JSON: " . $e->getMessage()); Yii::$app->response->statusCode = 400; + file_put_contents( + self::OUT_DIR . '/notification_error.txt', + PHP_EOL . date("d.m.Y H:i:s", time()) . " " . $e->getMessage() . $e->getLine(), + FILE_APPEND + ); return $this->asJson([ 'error' => [ 'type' => 'WRONG_EVENT_FORMAT', @@ -285,6 +298,11 @@ class NotificationController extends Controller $returnedAt = $orderReturnData['returnedAt']; } catch (\Exception $e) { Yii::$app->response->statusCode = 400; + file_put_contents( + self::OUT_DIR . '/notification_error.txt', + PHP_EOL . date("d.m.Y H:i:s", time()) . $e->getMessage() . $e->getLine(), + FILE_APPEND + ); return $this->asJson([ 'error' => [ 'type' => 'WRONG_EVENT_FORMAT', @@ -339,6 +357,11 @@ class NotificationController extends Controller default: Yii::info("Неизвестный тип события: {$eventType}"); + file_put_contents( + self::OUT_DIR . '/notification_error.txt', + PHP_EOL . date("d.m.Y H:i:s", time()) . " Неизвестный тип события: {$eventType}", + FILE_APPEND + ); return $this->asJson([ 'success' => true, 'message' => 'Unknown event ignored' @@ -346,6 +369,11 @@ class NotificationController extends Controller } } catch (\Exception $e) { Yii::error("Error processing event {$eventType}: " . $e->getMessage()); + file_put_contents( + self::OUT_DIR . '/notification_error.txt', + PHP_EOL . date("d.m.Y H:i:s", time()) . $e->getMessage() . $e->getLine(), + FILE_APPEND + ); Yii::$app->response->statusCode = 500; return $this->asJson([ 'error' => [