From 37893d2b8ec761c7c246d819da573f0b1b01df63 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 7 Sep 2026 07:26:50 +0200 Subject: [PATCH] Construct logger separately and pass it into NewCommon This is a preparation for passing only the logger to daemon.Handle instead of the whole common. --- pkg/app/app.go | 7 +++---- pkg/app/entry_point.go | 6 +++++- pkg/cheatsheet/generate.go | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 15a3f327a..11f50c8b5 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -61,10 +61,9 @@ func Run( } } -func NewCommon(config config.AppConfigurer) (*common.Common, error) { +func NewCommon(config config.AppConfigurer, log *logrus.Entry) (*common.Common, error) { userConfig := config.GetUserConfig() appState := config.GetAppState() - log := newLogger(config) // Initialize with English for the time being; the real translation set for // the configured language will be read after reading the user config tr := i18n.EnglishTranslationSet() @@ -80,8 +79,8 @@ func NewCommon(config config.AppConfigurer) (*common.Common, error) { return cmn, nil } -func newLogger(cfg config.AppConfigurer) *logrus.Entry { - if cfg.GetDebug() { +func NewLogger(debug bool) *logrus.Entry { + if debug { logPath, err := config.LogPath() if err != nil { log.Fatal(err) diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go index 31963d371..fcffeb64b 100644 --- a/pkg/app/entry_point.go +++ b/pkg/app/entry_point.go @@ -93,6 +93,10 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes env.SetGitDirEnv(cliArgs.GitDir) } + // The log file lives in the config dir, so this must come after setting the + // CONFIG_DIR env var above. + logger := NewLogger(cliArgs.Debug) + if cliArgs.PrintVersionInfo { gitVersion := getGitVersionInfo() fmt.Printf("commit=%s, build date=%s, build source=%s, version=%s, os=%s, arch=%s, git version=%s\n", buildInfo.Commit, buildInfo.Date, buildInfo.BuildSource, buildInfo.Version, runtime.GOOS, runtime.GOARCH, gitVersion) @@ -154,7 +158,7 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes appConfig.SaveGlobalUserConfig() } - common, err := NewCommon(appConfig) + common, err := NewCommon(appConfig, logger) if err != nil { log.Fatal(err) } diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index 5c5a94530..ab4f764f8 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -58,10 +58,11 @@ func generateAtDir(cheatsheetDir string) { log.Fatal(err) } mConfig := config.NewDummyAppConfig() + logger := app.NewLogger(mConfig.GetDebug()) for lang := range translationSetsByLang { mConfig.GetUserConfig().Gui.Language = lang - common, err := app.NewCommon(mConfig) + common, err := app.NewCommon(mConfig, logger) if err != nil { log.Fatal(err) }