From 02656b624db7106b844be8c6cc6ff4bad6dce75c Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 25 May 2023 15:17:00 +0200 Subject: [PATCH] Create log directory if required Signed-off-by: Evan Lezar --- internal/runtime/logger.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/runtime/logger.go b/internal/runtime/logger.go index 4fab3b60..b3122acc 100644 --- a/internal/runtime/logger.go +++ b/internal/runtime/logger.go @@ -156,11 +156,16 @@ func (l *Logger) Reset() error { } func createLogFile(filename string) (*os.File, error) { - if filename != "" && filename != os.DevNull { - return os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if filename == "" || filename == os.DevNull { + return nil, nil } - - return nil, nil + if dir := filepath.Dir(filepath.Clean(filename)); dir != "." { + err := os.MkdirAll(dir, 0755) + if err != nil { + return nil, err + } + } + return os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) } type loggerConfig struct {