Просмотр исходного кода

```
feat(log): 为阿里巴巴代理商服务配置专用日志通道

- 将1688分销采购请求日志重定向到alibaba日志通道
- 将1688分销采购响应日志重定向到alibaba日志通道
- 将1688分销采购错误日志重定向到alibaba日志通道
- 为商品入库服务配置专用的alibaba日志记录
- 在配置文件中添加alibaba日志通道设置
- 保留旧文件日志方式作为兼容性支持
```

shichen месяцев назад: 3
Родитель
Сommit
07bd98c597

+ 4 - 4
app/services/ThirdParty/AlibabaAgent/AlibabaAgentBaseService.php

@@ -376,7 +376,7 @@ class AlibabaAgentBaseService
376 376
             'params' => $this->maskSensitiveData($params),
377 377
         ];
378 378
 
379
-        Log::info('[1688分销采购] 请求: ' . json_encode($logData, JSON_UNESCAPED_UNICODE));
379
+        Log::channel('alibaba')->info('[1688分销采购] 请求: ' . json_encode($logData, JSON_UNESCAPED_UNICODE));
380 380
     }
381 381
 
382 382
     /**
@@ -391,7 +391,7 @@ class AlibabaAgentBaseService
391 391
             return;
392 392
         }
393 393
 
394
-        Log::info('[1688分销采购] 响应: ' . substr((string)$response, 0, 2000));
394
+        Log::channel('alibaba')->info('[1688分销采购] 响应: ' . substr((string)$response, 0, 2000));
395 395
     }
396 396
 
397 397
     /**
@@ -402,9 +402,9 @@ class AlibabaAgentBaseService
402 402
      */
403 403
     protected function logError(string $title, string $message): void
404 404
     {
405
-        Log::error("[1688分销采购] {$title}: {$message}");
405
+        Log::channel('alibaba')->error("[1688分销采购] {$title}: {$message}");
406 406
 
407
-        // 同时写入文件日志
407
+        // 同时写入文件日志(兼容旧的文件日志方式)
408 408
         $logPath = $this->config['logPath'] ?? runtime_path() . 'alibaba/';
409 409
         $logFile = $logPath . 'error_' . date('Y-m-d') . '.log';
410 410
         $logDir = dirname($logFile);

+ 3 - 3
app/services/ThirdParty/AlibabaAgent/ProductService.php

@@ -383,7 +383,7 @@ class ProductService extends AlibabaAgentBaseService
383 383
 
384 384
                 if ($exists) {
385 385
                     $success[$productId] = $exists['id'];
386
-                    Log::info("[1688入库] 商品{$productId}已存在,跳过入库,本地ID:{$exists['id']}");
386
+                    Log::channel('alibaba')->info("[1688入库] 商品{$productId}已存在,跳过入库,本地ID:{$exists['id']}");
387 387
                     continue;
388 388
                 }
389 389
 
@@ -433,13 +433,13 @@ class ProductService extends AlibabaAgentBaseService
433 433
 
434 434
                 if ($localId) {
435 435
                     $success[$productId] = $localId;
436
-                    Log::info("[1688入库] 商品{$productId}入库成功,本地ID:{$localId},已加价50%");
436
+                    Log::channel('alibaba')->info("[1688入库] 商品{$productId}入库成功,本地ID:{$localId},已加价50%");
437 437
                 } else {
438 438
                     $fail[$productId] = '写入数据库失败';
439 439
                 }
440 440
             } catch (\Throwable $e) {
441 441
                 $fail[$productId] = '异常: ' . $e->getMessage();
442
-                Log::error("[1688入库] 商品{$productId}入库异常: " . $e->getMessage());
442
+                Log::channel('alibaba')->error("[1688入库] 商品{$productId}入库异常: " . $e->getMessage());
443 443
             }
444 444
         }
445 445
 

+ 6 - 0
config/log.php

@@ -47,6 +47,12 @@ return [
47 47
             'path' => app()->getRootPath().'runtime/gong',
48 48
             'time_format' => 'Y-m-d H:i:s',
49 49
             'format' => '[%s][%s]:%s'
50
+        ],
51
+        'alibaba' => [
52
+            'type' => 'File',
53
+            'path' => app()->getRootPath().'runtime/alibaba',
54
+            'time_format' => 'Y-m-d H:i:s',
55
+            'format' => '[%s][%s]:%s'
50 56
         ]
51 57
     ],
52 58