From 6bc7fb3fece7286f601121d84706c47acf759682 Mon Sep 17 00:00:00 2001 From: Berger Eugene Date: Mon, 27 Feb 2023 00:54:36 +0200 Subject: [PATCH] Separate file for client --- src/config/config.go | 18 +++++++++++++++++- src/main.go | 3 +-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/config/config.go b/src/config/config.go index b2bcf09..f22612b 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -28,7 +28,9 @@ const ( LogFileMode = os.FileMode(0600) ) -var LogFilePath = filepath.Join(os.TempDir(), fmt.Sprintf("process-compose-%s.log", mustUser())) +func GetLogFilePath() string { + return filepath.Join(os.TempDir(), fmt.Sprintf("process-compose-%s%s.log", mustUser(), mode())) +} func procCompHome() string { if env := os.Getenv(pcConfigEnv); env != "" { @@ -58,3 +60,17 @@ func mustUser() string { } return usr.Username } + +func mode() string { + if isClient() { + return "-client" + } + return "" +} + +func isClient() bool { + if len(os.Args) > 1 { + return os.Args[1] == "process" + } + return false +} diff --git a/src/main.go b/src/main.go index 9e7d2a9..80a4d7c 100644 --- a/src/main.go +++ b/src/main.go @@ -21,8 +21,7 @@ func setupLogger(output io.Writer) { } func main() { - - file, err := os.OpenFile(config.LogFilePath, config.LogFileFlags, config.LogFileMode) + file, err := os.OpenFile(config.GetLogFilePath(), config.LogFileFlags, config.LogFileMode) if err != nil { panic(err) }