fix: 确保日志目录存在以避免写入失败
在写入日志前检查目录是否存在,不存在时自动创建,防止因目录缺失导致的日志写入失败
This commit is contained in:
@@ -66,6 +66,13 @@ function log_message($message, $type = 'info') {
|
||||
global $log_file;
|
||||
$timestamp = date('Y-m-d H:i:s');
|
||||
$log_entry = "[$timestamp] [$type] $message\n";
|
||||
|
||||
// 检查日志目录是否存在,如果不存在则创建
|
||||
$log_dir = dirname($log_file);
|
||||
if (!is_dir($log_dir)) {
|
||||
mkdir($log_dir, 0755, true);
|
||||
}
|
||||
|
||||
file_put_contents($log_file, $log_entry, FILE_APPEND);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user