Skip to content

Commit

Permalink
Merge pull request #108 from hatappi/replace-retryablehttp-logger-wit…
Browse files Browse the repository at this point in the history
…h-slog

Replace retryablehttp logger with slog
  • Loading branch information
hatappi authored Oct 14, 2023
2 parents 3c3cda6 + 3996066 commit e42ceae
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions log/retryablehttp/leveled_logger.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package retryablehttp

import (
"github.com/go-logr/logr"
"log/slog"

go_retryablehttp "github.com/hashicorp/go-retryablehttp"
)

type retryablehttpLeveledLogger struct {
logger logr.Logger
logger *slog.Logger
}

// NewRetryablehttpLeveledLogger initializes the LeveledLogger of go-retryablehttp package
func NewRetryablehttpLeveledLogger(logger logr.Logger) go_retryablehttp.LeveledLogger {
func NewRetryablehttpLeveledLogger(logger *slog.Logger) go_retryablehttp.LeveledLogger {
return retryablehttpLeveledLogger{
logger: logger,
}
Expand All @@ -20,7 +21,7 @@ func NewRetryablehttpLeveledLogger(logger logr.Logger) go_retryablehttp.LeveledL
func (rll retryablehttpLeveledLogger) Debug(msg string, keysAndValues ...interface{}) {
keysAndValues = append(keysAndValues, "retryablehttp_log_level", "debug")

rll.logger.V(1).Info(msg, keysAndValues...)
rll.logger.Debug(msg, keysAndValues...)
}

// Info outputs info log
Expand All @@ -30,16 +31,16 @@ func (rll retryablehttpLeveledLogger) Info(msg string, keysAndValues ...interfac
rll.logger.Info(msg, keysAndValues...)
}

// Info outputs warn log
// Warn outputs warn log
func (rll retryablehttpLeveledLogger) Warn(msg string, keysAndValues ...interface{}) {
keysAndValues = append(keysAndValues, "retryablehttp_log_level", "warn")

rll.logger.Info(msg, keysAndValues...)
rll.logger.Warn(msg, keysAndValues...)
}

// Info outputs error log
// Error outputs error log
func (rll retryablehttpLeveledLogger) Error(msg string, keysAndValues ...interface{}) {
keysAndValues = append(keysAndValues, "retryablehttp_log_level", "error")

rll.logger.Error(nil, msg, keysAndValues...)
rll.logger.Error(msg, keysAndValues...)
}

0 comments on commit e42ceae

Please sign in to comment.