From 23d3e54ddb9507c2f8ac6abc48f831830f9354ce Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Thu, 13 Oct 2022 04:24:52 +0200 Subject: [PATCH] Other: Move log init to proper place --- internal/app/app.go | 13 ++++++++++++- internal/app/logging.go | 28 ---------------------------- 2 files changed, 12 insertions(+), 29 deletions(-) delete mode 100644 internal/app/logging.go diff --git a/internal/app/app.go b/internal/app/app.go index 80588288..8f8f483a 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -16,6 +16,7 @@ import ( "github.com/ProtonMail/proton-bridge/v2/internal/events" "github.com/ProtonMail/proton-bridge/v2/internal/focus" "github.com/ProtonMail/proton-bridge/v2/internal/locations" + "github.com/ProtonMail/proton-bridge/v2/internal/logging" "github.com/ProtonMail/proton-bridge/v2/internal/sentry" "github.com/ProtonMail/proton-bridge/v2/internal/useragent" "github.com/ProtonMail/proton-bridge/v2/internal/vault" @@ -201,10 +202,20 @@ func withSingleInstance(locations *locations.Locations, version *semver.Version, // Initialize our logging system. func withLogging(c *cli.Context, crashHandler *crash.Handler, locations *locations.Locations, fn func() error) error { - if err := initLogging(c, locations, crashHandler); err != nil { + // Get a place to keep our logs. + logsPath, err := locations.ProvideLogsPath() + if err != nil { + return fmt.Errorf("could not provide logs path: %w", err) + } + + // Initialize logging. + if err := logging.Init(logsPath, c.String(flagLogLevel)); err != nil { return fmt.Errorf("could not initialize logging: %w", err) } + // Ensure we dump a stack trace if we crash. + crashHandler.AddRecoveryAction(logging.DumpStackTrace(logsPath)) + logrus. WithField("appName", constants.FullAppName). WithField("version", constants.Version). diff --git a/internal/app/logging.go b/internal/app/logging.go deleted file mode 100644 index 253b595d..00000000 --- a/internal/app/logging.go +++ /dev/null @@ -1,28 +0,0 @@ -package app - -import ( - "fmt" - - "github.com/ProtonMail/proton-bridge/v2/internal/crash" - "github.com/ProtonMail/proton-bridge/v2/internal/locations" - "github.com/ProtonMail/proton-bridge/v2/internal/logging" - "github.com/urfave/cli/v2" -) - -func initLogging(c *cli.Context, locations *locations.Locations, crashHandler *crash.Handler) error { - // Get a place to keep our logs. - logsPath, err := locations.ProvideLogsPath() - if err != nil { - return fmt.Errorf("could not provide logs path: %w", err) - } - - // Initialize logging. - if err := logging.Init(logsPath, c.String(flagLogLevel)); err != nil { - return fmt.Errorf("could not initialize logging: %w", err) - } - - // Ensure we dump a stack trace if we crash. - crashHandler.AddRecoveryAction(logging.DumpStackTrace(logsPath)) - - return nil -}