From ddd6f4be8ce3f0843064eff2f013291d67a57eb4 Mon Sep 17 00:00:00 2001 From: Shubham Hibare Date: Mon, 2 Sep 2024 22:51:34 +0530 Subject: [PATCH] fix errors --- cmd/backup/backup.go | 6 ++-- cmd/config/clean.go | 5 +-- cmd/root.go | 14 ++++---- go.mod | 3 -- go.sum | 14 -------- internal/backup/backup.go | 59 +++++++++++++++++---------------- internal/config/config.go | 25 +++++++------- internal/constants/constants.go | 2 +- internal/notifiers/discord.go | 21 ++++++------ internal/notifiers/notifier.go | 8 ++--- 10 files changed, 71 insertions(+), 86 deletions(-) diff --git a/cmd/backup/backup.go b/cmd/backup/backup.go index 2e61215..50984e8 100644 --- a/cmd/backup/backup.go +++ b/cmd/backup/backup.go @@ -1,9 +1,8 @@ package backup import ( - "errors" + "log/slog" - log "github.com/rs/zerolog/log" "github.com/spf13/cobra" ) @@ -12,9 +11,8 @@ var BackupCmd = &cobra.Command{ Short: "Perform backups & related operations", Long: "", Run: func(cmd *cobra.Command, args []string) { - log.Error().Err(errors.New("test error")).Msg("Printing help") if err := cmd.Help(); err != nil { - log.Error().Err(err).Msg("error printing help") + slog.Error("error printing help") } }, } diff --git a/cmd/config/clean.go b/cmd/config/clean.go index 1f0302e..a65e400 100644 --- a/cmd/config/clean.go +++ b/cmd/config/clean.go @@ -1,8 +1,9 @@ package config import ( + "log/slog" + "github.com/hibare/GoS3Backup/internal/config" - "github.com/rs/zerolog/log" "github.com/spf13/cobra" ) @@ -11,7 +12,7 @@ var CleanConfigCmd = &cobra.Command{ Short: "Command to clean up program config", Run: func(cmd *cobra.Command, args []string) { if err := config.CleanConfig(); err != nil { - log.Error().Err(err).Msg("error cleaning config") + slog.Error("error cleaning config", "error", err) } }, } diff --git a/cmd/root.go b/cmd/root.go index 6198a88..a9034a1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,6 +1,7 @@ package cmd import ( + "log/slog" "os" "time" @@ -12,7 +13,6 @@ import ( "github.com/hibare/GoS3Backup/internal/config" "github.com/hibare/GoS3Backup/internal/constants" "github.com/hibare/GoS3Backup/internal/version" - "github.com/rs/zerolog/log" "github.com/spf13/cobra" ) @@ -30,15 +30,15 @@ var rootCmd = &cobra.Command{ intBackup.Backup() intBackup.PurgeOldBackups() }); err != nil { - log.Error().Err(err).Msg("Error setting up cron") + slog.Error("Error setting up cron") } - log.Info().Msgf("Scheduled backup job to run every %s", config.Current.Backup.Cron) + slog.Info("Scheduled backup job", "cron", config.Current.Backup.Cron) // Schedule version check job - if _, err := s.Cron(constants.VersioCheckCron).Do(func() { + if _, err := s.Cron(constants.VersionCheckCron).Do(func() { version.V.CheckUpdate() }); err != nil { - log.Warn().Err(err).Msg("Failed to schedule version check job") + slog.Warn("Failed to schedule version check job") } s.StartBlocking() @@ -56,12 +56,12 @@ func init() { rootCmd.AddCommand(configCmd.ConfigCmd) rootCmd.AddCommand(backup.BackupCmd) - cobra.OnInitialize(commonLogger.InitLogger, config.LoadConfig) + cobra.OnInitialize(commonLogger.InitDefaultLogger, config.LoadConfig) initialVersionCheck := func() { version.V.CheckUpdate() if version.V.NewVersionAvailable { - log.Info().Msg(version.V.GetUpdateNotification()) + slog.Info(version.V.GetUpdateNotification()) } } go initialVersionCheck() diff --git a/go.mod b/go.mod index c11cf34..fd02ed5 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/go-co-op/gocron v1.37.0 github.com/hibare/GoCommon/v2 v2.13.0 github.com/jedib0t/go-pretty/v6 v6.5.9 - github.com/rs/zerolog v1.33.0 github.com/spf13/cobra v1.8.1 ) @@ -20,8 +19,6 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/magiconair/properties v1.8.7 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect diff --git a/go.sum b/go.sum index c194d36..d06480e 100644 --- a/go.sum +++ b/go.sum @@ -4,7 +4,6 @@ github.com/aws/aws-sdk-go v1.55.3 h1:0B5hOX+mIx7I5XPOrjrHlKSDQV/+ypFZpIHOx5LOk3E github.com/aws/aws-sdk-go v1.55.3/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -17,7 +16,6 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0= github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= @@ -45,11 +43,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -57,7 +50,6 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -69,9 +61,6 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= -github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= @@ -110,9 +99,6 @@ golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= diff --git a/internal/backup/backup.go b/internal/backup/backup.go index edcf419..d81a7bf 100644 --- a/internal/backup/backup.go +++ b/internal/backup/backup.go @@ -5,7 +5,7 @@ import ( "os" "path/filepath" - "github.com/rs/zerolog/log" + "log/slog" commonGPG "github.com/hibare/GoCommon/v2/pkg/crypto/gpg" commonDateTimes "github.com/hibare/GoCommon/v2/pkg/datetime" @@ -33,80 +33,81 @@ func Backup() { s3.SetPrefix(config.Current.S3.Prefix, config.Current.Backup.Hostname, true) if err := s3.NewSession(); err != nil { - log.Fatal().Err(err).Msg("Error creating session") + slog.Error("Error creating session", "error", err) + os.Exit(1) return } // Loop through individual backup dir & perform backup for _, dir := range config.Current.Backup.Dirs { - log.Info().Msgf("Processing path %s", dir) + slog.Info("Processing path", "path", dir) if config.Current.Backup.ArchiveDirs { - log.Info().Msgf("Archiving dir %s", dir) + slog.Info("Archiving dir", "dir", dir) archivePath, totalFiles, totalDirs, successFiles, err := commonFiles.ArchiveDir(dir, nil) if err != nil { - log.Error().Err(err).Msgf("Archiving failed %s", dir) + slog.Error("Error archiving", "error", err) notifiers.NotifyBackupFailure(dir, totalDirs, totalFiles, err) continue } if successFiles <= 0 { - log.Error().Err(err).Msgf("Uploading failed %s", dir) + slog.Error("No processable files", "dir", dir) notifiers.NotifyBackupFailure(dir, totalDirs, totalFiles, ErrNoProcessableFiles) continue } - log.Info().Msgf("Archived files %d/%d, archive path %s", successFiles, totalFiles, archivePath) + slog.Info("Archived files", "successFiles", successFiles, "totalFiles", totalFiles, "archivePath", archivePath) uploadPath := archivePath if config.Current.Backup.Encryption.Enabled { - log.Info().Msgf("Encrypting archive %s", archivePath) + slog.Info("Encrypting archive", "archivePath", archivePath) gpg, err := commonGPG.DownloadGPGPubKey(config.Current.Backup.Encryption.GPG.KeyID, config.Current.Backup.Encryption.GPG.KeyServer) if err != nil { - log.Error().Err(err).Msg("Error downloading gpg key") + slog.Error("Error downloading gpg key", "error", err) notifiers.NotifyBackupFailure(dir, totalDirs, totalFiles, err) continue } encryptedFilePath, err := gpg.EncryptFile(archivePath) if err != nil { - log.Error().Err(err).Msg("Error encrypting file") + slog.Error("Error encrypting file", "error", err) notifiers.NotifyBackupFailure(dir, totalDirs, totalFiles, err) continue } uploadPath = encryptedFilePath - log.Info().Msgf("Archive encrypted at %s", encryptedFilePath) + slog.Info("Encrypted archive", "uploadPath", uploadPath) os.Remove(archivePath) } - log.Info().Msgf("Uploading file %s", uploadPath) + slog.Info("Uploading file", "uploadPath", uploadPath) key, err := s3.UploadFile(uploadPath) if err != nil { - log.Error().Err(err).Msgf("Uploading failed %s", dir) + slog.Error("Uploading failed", "error", err) notifiers.NotifyBackupFailure(dir, totalDirs, totalFiles, err) continue } - log.Info().Msgf("Uploaded files %d/%d at %s", successFiles, totalFiles, key) + slog.Info("Uploaded file", "key", key, "successFiles", successFiles, "totalFiles", totalFiles, "uploadPath", uploadPath) notifiers.NotifyBackupSuccess(dir, totalDirs, totalFiles, successFiles, key) os.Remove(uploadPath) } else { - log.Info().Msgf("Uploading dir %s", dir) + slog.Info("Uploading dir", "dir", dir) key, totalFiles, totalDirs, successFiles := s3.UploadDir(dir, nil) if successFiles <= 0 { - log.Warn().Msgf("Uploading failed %s", dir) + slog.Warn("No processable files", "dir", dir) notifiers.NotifyBackupFailure(dir, totalDirs, totalFiles, ErrNoProcessableFiles) continue } - log.Warn().Msgf("Uploaded files %d/%d at %s", successFiles, totalFiles, s3.Prefix) + slog.Warn("Uploaded files", "successFiles", successFiles, "totalFiles", totalFiles, "dir", dir) notifiers.NotifyBackupSuccess(dir, totalDirs, totalFiles, successFiles, key) } } - log.Info().Msg("Backup job ran successfully") + slog.Info("Backup job ran successfully") } func ListBackups() ([]string, error) { @@ -123,25 +124,25 @@ func ListBackups() ([]string, error) { s3.SetPrefix(config.Current.S3.Prefix, config.Current.Backup.Hostname, false) if err := s3.NewSession(); err != nil { - log.Error().Err(err).Msg("Error creating session") + slog.Error("Error creating session", "error", err) return keys, err } - log.Info().Msgf("prefix: %s", s3.Prefix) + slog.Info("prefix", "prefix", s3.Prefix) // Retrieve objects by prefix keys, err := s3.ListObjectsAtPrefixRoot() if err != nil { - log.Error().Err(err).Msg("Error listing objects") + slog.Error("Error listing objects", "error", err) return keys, err } if len(keys) == 0 { - log.Info().Msg("No backups found") + slog.Info("No backups found") return keys, nil } - log.Info().Msgf("Found %d backups", len(keys)) + slog.Info("Found backups", "keys", len(keys)) // Remove prefix from key to get datetime string keys = s3.TrimPrefix(keys) @@ -163,7 +164,7 @@ func PurgeOldBackups() { s3.SetPrefix(config.Current.S3.Prefix, config.Current.Backup.Hostname, false) if err := s3.NewSession(); err != nil { - log.Error().Err(err).Msg("Error creating session") + slog.Error("Error creating session", "error", err) } backups, err := ListBackups() @@ -173,24 +174,24 @@ func PurgeOldBackups() { } if len(backups) <= int(config.Current.Backup.RetentionCount) { - log.Info().Msg("No backups to delete") + slog.Info("No backups to delete") return } keysToDelete := backups[config.Current.Backup.RetentionCount:] - log.Info().Msgf("Found %d backups to delete (backup rentention %d) [%s]", len(keysToDelete), config.Current.Backup.RetentionCount, keysToDelete) + slog.Info("Found backups to delete", "backups", len(keysToDelete), "retention", config.Current.Backup.RetentionCount, "keys", keysToDelete) // Delete datetime keys from S3 exceding retention count for _, key := range keysToDelete { - log.Info().Msgf("Deleting backup %s", key) + slog.Info("Deleting backup", "key", key) key = filepath.Join(s3.Prefix, key) if err := s3.DeleteObjects(key, true); err != nil { - log.Error().Err(err).Msgf("Error deleting backup %s", key) + slog.Error("Error deleting backup", "key", key, "error", err) notifiers.NotifyBackupDeleteFailure(key, err) continue } } - log.Info().Msg("Deletion completed successfully") + slog.Info("Deletion completed successfully") } diff --git a/internal/config/config.go b/internal/config/config.go index c13145a..1f2f303 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,11 +1,13 @@ package config import ( + "log" + "log/slog" + commonConfig "github.com/hibare/GoCommon/v2/pkg/config" commonLogger "github.com/hibare/GoCommon/v2/pkg/logger" commonUtils "github.com/hibare/GoCommon/v2/pkg/utils" "github.com/hibare/GoS3Backup/internal/constants" - "github.com/rs/zerolog/log" ) type S3Config struct { @@ -66,7 +68,7 @@ var BC commonConfig.BaseConfig func LoadConfig() { current, err := BC.ReadYAMLConfig(Current) if err != nil { - log.Fatal().Err(err).Msg("Error reading config file") + log.Fatalf("Error reading config file: %s", err) } Current = current.(*Config) @@ -75,7 +77,7 @@ func LoadConfig() { Current.Logger.Level = commonLogger.DefaultLoggerLevel } else if Current.Logger.Level != "" { if !commonLogger.IsValidLogLevel(Current.Logger.Level) { - log.Fatal().Str("level", Current.Logger.Level).Msg("Error invalid logger level") + log.Fatalf("Error invalid logger level: %s", Current.Logger.Level) } } @@ -83,29 +85,27 @@ func LoadConfig() { Current.Logger.Mode = commonLogger.DefaultLoggerMode } else if Current.Logger.Mode != "" { if !commonLogger.IsValidLogMode(Current.Logger.Mode) { - log.Fatal().Str("mode", Current.Logger.Mode).Msg("Error invalid logger mode") + log.Fatalf("Error invalid logger mode: %s", Current.Logger.Mode) } } - // Set logger level & mode - commonLogger.SetLoggingLevel(Current.Logger.Level) - commonLogger.SetLoggingMode(Current.Logger.Mode) + commonLogger.InitLogger(&Current.Logger.Level, &Current.Logger.Mode) // Set default DateTimeLayout if missing if Current.Backup.DateTimeLayout == "" { - log.Warn().Msgf("DateTimeLayout is not set, using default: %s", constants.DefaultDateTimeLayout) + slog.Warn("DateTimeLayout is not set, using default", "default", constants.DefaultDateTimeLayout) Current.Backup.DateTimeLayout = constants.DefaultDateTimeLayout } // Set RetentionCount if missing if Current.Backup.RetentionCount == 0 { - log.Warn().Msgf("RetentionCount is not set, using default: %d", constants.DefaultRetentionCount) + slog.Warn("RetentionCount is not set, using default", "default", constants.DefaultRetentionCount) Current.Backup.RetentionCount = constants.DefaultRetentionCount } // Set Schedule if missing if Current.Backup.Cron == "" { - log.Warn().Msgf("Schedule is not set, using default: %s", constants.DefaultCron) + slog.Warn("Schedule is not set, using default", "default", constants.DefaultCron) Current.Backup.Cron = constants.DefaultCron } @@ -116,11 +116,12 @@ func LoadConfig() { // Check if encryption is enabled & encryption config is enabled if Current.Backup.Encryption.Enabled && !Current.Backup.ArchiveDirs { - log.Warn().Msg("Backup encryption is only available when archive dirs are enabled. Disabling encryption") + slog.Warn("Backup encryption is only available when archive dirs are enabled. Disabling encryption") Current.Backup.Encryption.Enabled = false } else if Current.Backup.Encryption.Enabled { if Current.Backup.Encryption.GPG.KeyServer == "" || Current.Backup.Encryption.GPG.KeyID == "" { - log.Fatal().Msg("Error backup encryption is enabled but encryption config is not set") + slog.Error("Encryption is enabled but GPG key server or key ID is missing") + Current.Backup.Encryption.Enabled = false } } diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 8ae06ba..579a1eb 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -5,7 +5,7 @@ const ( DefaultDateTimeLayout = "20060102150405" DefaultRetentionCount = 30 DefaultCron = "0 0 * * *" - VersioCheckCron = "0 0 * * *" + VersionCheckCron = "0 0 * * *" NotAvailable = "N/A" GithubOwner = "hibare" ) diff --git a/internal/notifiers/discord.go b/internal/notifiers/discord.go index 9dfc456..6021849 100644 --- a/internal/notifiers/discord.go +++ b/internal/notifiers/discord.go @@ -2,13 +2,13 @@ package notifiers import ( "fmt" + "log/slog" "strconv" "github.com/hibare/GoCommon/v2/pkg/notifiers/discord" "github.com/hibare/GoS3Backup/internal/config" "github.com/hibare/GoS3Backup/internal/constants" "github.com/hibare/GoS3Backup/internal/version" - "github.com/rs/zerolog/log" ) func runDiscordPrechecks() error { @@ -20,7 +20,7 @@ func runDiscordPrechecks() error { func discordNotifyBackupSuccess(directory string, totalDirs, totalFiles, successFiles int, key string) { if err := runDiscordPrechecks(); err != nil { - log.Error().Err(err).Msg("error running discord prechecks") + slog.Error("error running discord prechecks", "error", err) return } @@ -56,18 +56,18 @@ func discordNotifyBackupSuccess(directory string, totalDirs, totalFiles, success if version.V.NewVersionAvailable { if err := message.AddFooter(version.V.GetUpdateNotification()); err != nil { - log.Error().Err(err) + slog.Error("error adding footer to message", "error", err) } } if err := message.Send(config.Current.Notifiers.Discord.Webhook); err != nil { - log.Error().Err(err) + slog.Error("error sending discord message", "error", err) } } func discordNotifyBackupFailure(directory string, totalDirs, totalFiles int, err error) { if err := runDiscordPrechecks(); err != nil { - log.Error().Err(err) + slog.Error("error running discord prechecks", "error", err) return } @@ -103,18 +103,18 @@ func discordNotifyBackupFailure(directory string, totalDirs, totalFiles int, err if version.V.NewVersionAvailable { if err := message.AddFooter(version.V.GetUpdateNotification()); err != nil { - log.Error().Err(err) + slog.Error("error adding footer to message", "error", err) } } if err := message.Send(config.Current.Notifiers.Discord.Webhook); err != nil { - log.Error().Err(err) + slog.Error("error sending discord message", "error", err) } } func discordNotifyBackupDeleteFailure(key string, err error) { if err := runDiscordPrechecks(); err != nil { - log.Error().Err(err) + slog.Error("error running discord prechecks", "error", err) return } @@ -140,11 +140,12 @@ func discordNotifyBackupDeleteFailure(key string, err error) { if version.V.NewVersionAvailable { if err := message.AddFooter(version.V.GetUpdateNotification()); err != nil { - log.Error().Err(err) + slog.Error("error adding footer to message", "error", err) + } } if err := message.Send(config.Current.Notifiers.Discord.Webhook); err != nil { - log.Error().Err(err) + slog.Error("error sending discord message", "error", err) } } diff --git a/internal/notifiers/notifier.go b/internal/notifiers/notifier.go index aafba42..0f3e4c6 100644 --- a/internal/notifiers/notifier.go +++ b/internal/notifiers/notifier.go @@ -2,9 +2,9 @@ package notifiers import ( "errors" + "log/slog" "github.com/hibare/GoS3Backup/internal/config" - "github.com/rs/zerolog/log" ) var ( @@ -23,7 +23,7 @@ func runPreChecks() error { func NotifyBackupSuccess(directory string, totalDirs, totalFiles, successFiles int, key string) { if err := runPreChecks(); err != nil { - log.Error().Err(err) + slog.Error("error running prechecks", "error", err) return } @@ -33,7 +33,7 @@ func NotifyBackupSuccess(directory string, totalDirs, totalFiles, successFiles i func NotifyBackupFailure(directory string, totalDirs, totalFiles int, err error) { if err := runPreChecks(); err != nil { - log.Error().Err(err) + slog.Error("error running prechecks", "error", err) return } @@ -43,7 +43,7 @@ func NotifyBackupFailure(directory string, totalDirs, totalFiles int, err error) func NotifyBackupDeleteFailure(key string, err error) { if err := runPreChecks(); err != nil { - log.Error().Err(err) + slog.Error("error running prechecks", "error", err) return }