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.
This commit is contained in:
Stefan Haller 2026-09-07 07:26:50 +02:00
parent 76311082a3
commit 37893d2b8e
3 changed files with 10 additions and 6 deletions

View file

@ -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)

View file

@ -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)
}

View file

@ -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)
}