From 8e335e054743b7a29863a89e73dd020ed9fe641d Mon Sep 17 00:00:00 2001 From: sunshinexcode <24xinhui@163.com> Date: Fri, 9 Aug 2024 16:10:17 +0800 Subject: [PATCH] chore(): modify default log path (#177) --- .env.example | 2 +- server/main.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 17141464..223eef68 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,7 @@ # ------------------------------ # Log path -LOG_PATH=/tmp +LOG_PATH=/tmp/astra # Graph designer server port GRAPH_DESIGNER_SERVER_PORT=49483 # Server port diff --git a/server/main.go b/server/main.go index 442e6506..d590b89d 100644 --- a/server/main.go +++ b/server/main.go @@ -20,6 +20,15 @@ func main() { slog.Warn("load .env file failed", "err", err) } + // Check if the directory exists + logPath := os.Getenv("LOG_PATH") + if _, err := os.Stat(logPath); os.IsNotExist(err) { + if err := os.MkdirAll(logPath, os.ModePerm); err != nil { + slog.Error("create log directory failed", "err", err) + os.Exit(1) + } + } + // Check environment agoraAppId := os.Getenv("AGORA_APP_ID") if len(agoraAppId) != 32 { @@ -49,7 +58,7 @@ func main() { httpServerConfig := &internal.HttpServerConfig{ AppId: agoraAppId, AppCertificate: os.Getenv("AGORA_APP_CERTIFICATE"), - LogPath: os.Getenv("LOG_PATH"), + LogPath: logPath, Port: os.Getenv("SERVER_PORT"), WorkersMax: workersMax, WorkerQuitTimeoutSeconds: workerQuitTimeoutSeconds,