From a205d8c04692faa212adf3ab0691d724731f2f16 Mon Sep 17 00:00:00 2001 From: Jakub Date: Thu, 25 Mar 2021 09:32:15 +0100 Subject: [PATCH] GODT-1120 hotfix: use Info level in internal/app logs --- internal/app/base/base.go | 1 - internal/app/base/migration.go | 2 +- internal/app/bridge/bridge.go | 13 +++++++------ internal/app/ie/ie.go | 7 ++++--- internal/logging/logging.go | 4 ++++ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/internal/app/base/base.go b/internal/app/base/base.go index b0c9cd0e..11a7254d 100644 --- a/internal/app/base/base.go +++ b/internal/app/base/base.go @@ -136,7 +136,6 @@ func New( // nolint[funlen] if err := logging.Init(logsPath); err != nil { return nil, err } - logging.SetLevel("debug") // Proper level is set later in run. crashHandler.AddRecoveryAction(logging.DumpStackTrace(logsPath)) if err := migrateFiles(configName); err != nil { diff --git a/internal/app/base/migration.go b/internal/app/base/migration.go index 07e9aad8..304f74b5 100644 --- a/internal/app/base/migration.go +++ b/internal/app/base/migration.go @@ -111,7 +111,7 @@ func moveIfExists(source, destination string) error { l := logrus.WithField("source", source).WithField("destination", destination) if _, err := os.Stat(source); os.IsNotExist(err) { - l.Debug("No need to migrate file, source doesn't exist") + l.Info("No need to migrate file, source doesn't exist") return nil } diff --git a/internal/app/bridge/bridge.go b/internal/app/bridge/bridge.go index d983b010..aa27bfbe 100644 --- a/internal/app/bridge/bridge.go +++ b/internal/app/bridge/bridge.go @@ -189,9 +189,10 @@ func generateTLSCerts(b *base.Base) error { } func checkAndHandleUpdate(u types.Updater, f frontend.Frontend, autoUpdate bool) { + log := logrus.WithField("pkg", "app/bridge") version, err := u.Check() if err != nil { - logrus.WithError(err).Error("An error occurred while checking for updates") + log.WithError(err).Error("An error occurred while checking for updates") return } @@ -201,11 +202,11 @@ func checkAndHandleUpdate(u types.Updater, f frontend.Frontend, autoUpdate bool) f.SetVersion(version) if !u.IsUpdateApplicable(version) { - logrus.Debug("No need to update") + log.Info("No need to update") return } - logrus.WithField("version", version.Version).Info("An update is available") + log.WithField("version", version.Version).Info("An update is available") if !autoUpdate { f.NotifyManualUpdate(version, u.CanInstall(version)) @@ -213,16 +214,16 @@ func checkAndHandleUpdate(u types.Updater, f frontend.Frontend, autoUpdate bool) } if !u.CanInstall(version) { - logrus.Info("A manual update is required") + log.Info("A manual update is required") f.NotifySilentUpdateError(updater.ErrManualUpdateRequired) return } if err := u.InstallUpdate(version); err != nil { if errors.Cause(err) == updater.ErrDownloadVerify { - logrus.WithError(err).Warning("Skipping update installation due to temporary error") + log.WithError(err).Warning("Skipping update installation due to temporary error") } else { - logrus.WithError(err).Error("The update couldn't be installed") + log.WithError(err).Error("The update couldn't be installed") f.NotifySilentUpdateError(err) } diff --git a/internal/app/ie/ie.go b/internal/app/ie/ie.go index d3a1b55f..e6348311 100644 --- a/internal/app/ie/ie.go +++ b/internal/app/ie/ie.go @@ -87,9 +87,10 @@ func run(b *base.Base, c *cli.Context) error { } func checkAndHandleUpdate(u types.Updater, f frontend.Frontend, autoUpdate bool) { //nolint[unparam] + log := logrus.WithField("pkg", "app/ie") version, err := u.Check() if err != nil { - logrus.WithError(err).Error("An error occurred while checking for updates") + log.WithError(err).Error("An error occurred while checking for updates") return } @@ -99,11 +100,11 @@ func checkAndHandleUpdate(u types.Updater, f frontend.Frontend, autoUpdate bool) f.SetVersion(version) if !u.IsUpdateApplicable(version) { - logrus.Debug("No need to update") + log.Info("No need to update") return } - logrus.WithField("version", version.Version).Info("An update is available") + log.WithField("version", version.Version).Info("An update is available") f.NotifyManualUpdate(version, u.CanInstall(version)) } diff --git a/internal/logging/logging.go b/internal/logging/logging.go index 96796d5e..76c9328a 100644 --- a/internal/logging/logging.go +++ b/internal/logging/logging.go @@ -69,6 +69,10 @@ func Init(logsPath string) error { return nil } +// SetLevel will change the level of logging and in case of Debug or Trace +// level it will also prevent from writing to file. Setting level to Info or +// higher will not set writing to file again if it was previously cancelled by +// Debug or Trace. func SetLevel(level string) { if lvl, err := logrus.ParseLevel(level); err == nil { logrus.SetLevel(lvl)