|
@@ -28,6 +28,17 @@ class Log{
|
|
|
$maxFiles = empty($options['maxFiles']) ? 30 : $options['maxFiles'];
|
|
$maxFiles = empty($options['maxFiles']) ? 30 : $options['maxFiles'];
|
|
|
// 错误等级
|
|
// 错误等级
|
|
|
$logPath = empty($options['filename']) ? 'logs/'.$name.'/'. basename($name).'.log' : 'logs/'.$name.'/'.$options['filename'].'.log';
|
|
$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.
|
|
// 初始化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));
|
|
$log->pushHandler(new RotatingFileHandler(storage_path($logPath), $maxFiles,$level));
|
|
|
// 对应日志级别记录日志
|
|
// 对应日志级别记录日志
|