Forráskód Böngészése

[智价云] 日志目录错误修复

tangyuanwang 11 órája
szülő
commit
74cdfa2208
1 módosított fájl, 11 hozzáadás és 0 törlés
  1. 11 0
      app/Servers/Logs/Log.php

+ 11 - 0
app/Servers/Logs/Log.php

@@ -28,6 +28,17 @@ class Log{
         $maxFiles                           = empty($options['maxFiles']) ? 30 :  $options['maxFiles'];
         // 错误等级
         $logPath                            = empty($options['filename']) ? 'logs/'.$name.'/'. basename($name).'.log' : 'logs/'.$name.'/'.$options['filename'].'.log';
+        // ✅ 关键修复:自动创建日志目录
+        $fullPath = storage_path($logPath);
+        $logDir = dirname($fullPath);
+        if (!is_dir($logDir)) {
+            // 递归创建目录,权限 0755
+            if (!mkdir($logDir, 0755, true)) {
+                // 如果创建失败,记录到错误日志
+                error_log("Failed to create log directory: " . $logDir);
+                return;
+            }
+        }
         // 初始化Stores logs to files that are rotated every day and a limited number of files are kept.
         $log->pushHandler(new RotatingFileHandler(storage_path($logPath), $maxFiles,$level));
         // 对应日志级别记录日志