From 94eb034bd1571e3ed3a6a333b1f11fad8da231c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E4=B8=B6=E7=A7=8B=E7=A7=8B=E7=A7=8B=E7=A7=8B?= =?UTF-8?q?=E7=A7=8B?= <> Date: Mon, 19 Feb 2024 20:27:34 +0800 Subject: [PATCH] when write log, if logFile not set, create a default logFile --- src/Worker.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Worker.php b/src/Worker.php index be0d3e3d4..99d7d8cfe 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -2205,6 +2205,16 @@ public static function log(\Stringable|string $msg, bool $decorated = false): vo if (isset(static::$logFile)) { $pid = DIRECTORY_SEPARATOR === '/' ? posix_getpid() : 1; file_put_contents(static::$logFile, sprintf("%s pid:%d %s\n", date('Y-m-d H:i:s'), $pid, $msg), FILE_APPEND | LOCK_EX); + } else { + //if logFile not set, create a default logFile + if (!is_file(static::$logFile) && static::$logFile !== '/dev/null') { + // if /runtime/logs default folder not exists + if (!is_dir(dirname(static::$logFile))) { + @mkdir(dirname(static::$logFile), 0777, true); + } + touch(static::$logFile); + chmod(static::$logFile, 0644); + } } }