-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathlogger.go
52 lines (45 loc) · 1.5 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package session
import (
"github.com/apex/log"
"github.com/hashicorp/go-retryablehttp"
)
// GetRetryableLogger returns wrapper retryablehttp.LeveledLogger for log.Interface
func GetRetryableLogger(log log.Interface) retryablehttp.LeveledLogger {
return &retryableLogger{log: log}
}
// retryableLogger is wrapper for log.Interface to expose retryablehttp.LeveledLogger needed for retry logic
type retryableLogger struct {
log log.Interface
}
// Error level formatted message.
func (l *retryableLogger) Error(msg string, keysAndValues ...interface{}) {
kv := append([]interface{}{}, keysAndValues...)
switch msg {
case "request failed":
l.log.Errorf("%s %s request failed: %v", kv[1], kv[3], kv[5])
case "error reading response body":
l.log.Errorf("error reading response body: %v", kv[1])
default:
l.log.Errorf(msg, keysAndValues...)
}
}
// Info level formatted message.
func (l *retryableLogger) Info(msg string, keysAndValues ...interface{}) {
l.log.Infof(msg, keysAndValues...)
}
// Debug level formatted message.
func (l *retryableLogger) Debug(msg string, keysAndValues ...interface{}) {
kv := append([]interface{}{}, keysAndValues...)
switch msg {
case "retrying request":
l.log.Debugf("%s: retrying in %s (%d left)", kv[1], kv[3], kv[5])
case "performing request":
l.log.Debugf("%s %s", kv[1], kv[3])
default:
l.log.Debugf(msg, keysAndValues...)
}
}
// Warn level formatted message.
func (l *retryableLogger) Warn(msg string, keysAndValues ...interface{}) {
l.log.Warnf(msg, keysAndValues...)
}