diff --git a/internal/app/logging.go b/internal/app/logging.go index 7e8b0a1f..e0a4abb4 100644 --- a/internal/app/logging.go +++ b/internal/app/logging.go @@ -8,23 +8,19 @@ import ( ) type Logger struct { + *logger.Logger SlackWebhook string - baseLogger *logger.Logger -} - -func (l *Logger) Info(message string) { - l.baseLogger.Info(message) } func (l *Logger) Debug(message string) { if flags.debug { - l.baseLogger.Debug(message) + l.Logger.Debug(message) } } func (l *Logger) Verbose(message string) { if flags.verbose { - l.baseLogger.Info(message) + l.Logger.Info(message) } } @@ -32,33 +28,21 @@ func (l *Logger) Error(message string) { if _, err := url.ParseRequestURI(l.SlackWebhook); err == nil { notifySlack(message, l.SlackWebhook, true, flags.apply) } - l.baseLogger.Error(message) -} - -func (l *Logger) Errorf(message string, args ...interface{}) { - l.baseLogger.Errorf(message, args...) -} - -func (l *Logger) Warning(message string) { - l.baseLogger.Warning(message) -} - -func (l *Logger) Notice(message string) { - l.baseLogger.Notice(message) + l.Logger.Error(message) } func (l *Logger) Critical(message string) { if _, err := url.ParseRequestURI(l.SlackWebhook); err == nil { notifySlack(message, l.SlackWebhook, true, flags.apply) } - l.baseLogger.Critical(message) + l.Logger.Critical(message) } func (l *Logger) Fatal(message string) { if _, err := url.ParseRequestURI(l.SlackWebhook); err == nil { notifySlack(message, l.SlackWebhook, true, flags.apply) } - l.baseLogger.Fatal(message) + l.Logger.Fatal(message) } func initLogs(verbose bool, noColors bool) { @@ -71,5 +55,5 @@ func initLogs(verbose bool, noColors bool) { if noColors { colors = 0 } - log.baseLogger, _ = logger.New("logger", colors, os.Stdout, logLevel) + log.Logger, _ = logger.New("logger", colors, os.Stdout, logLevel) } diff --git a/internal/azure/azblob.go b/internal/azure/azblob.go index 20d16515..235a8bb9 100644 --- a/internal/azure/azblob.go +++ b/internal/azure/azblob.go @@ -23,7 +23,7 @@ var p pipeline.Pipeline // auth checks for AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY in the environment // if env vars are set, it will authenticate and create an azblob request pipeline // returns false and error message if credentials are not set or are invalid -func auth() (bool, string) { +func auth() error { accountName, accountKey = os.Getenv("AZURE_STORAGE_ACCOUNT"), os.Getenv("AZURE_STORAGE_ACCESS_KEY") if len(accountName) != 0 && len(accountKey) != 0 { log.Println("AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY are set in the environment. They will be used to connect to Azure storage.") @@ -31,19 +31,19 @@ func auth() (bool, string) { credential, err := azblob.NewSharedKeyCredential(accountName, accountKey) if err == nil { p = azblob.NewPipeline(credential, azblob.PipelineOptions{}) - return true, "" + return nil } - return false, err.Error() + return err } - return false, "either the AZURE_STORAGE_ACCOUNT or AZURE_STORAGE_ACCESS_KEY environment variable is not set" + return fmt.Errorf("either the AZURE_STORAGE_ACCOUNT or AZURE_STORAGE_ACCESS_KEY environment variable is not set") } // ReadFile reads a file from storage container and saves it in a desired location. func ReadFile(containerName string, filename string, outFile string, noColors bool) { style = aurora.NewAurora(!noColors) - if ok, err := auth(); !ok { - log.Fatal(style.Bold(style.Red("ERROR: " + err))) + if err := auth(); err != nil { + log.Fatal(style.Bold(style.Red("ERROR: " + err.Error()))) } URL, _ := url.Parse(