9
9
10
10
"github.com/gitpod-io/gitpod/common-go/log"
11
11
"github.com/hashicorp/go-retryablehttp"
12
+ "github.com/sirupsen/logrus"
12
13
)
13
14
14
15
type Option func (opts * httpOpts )
@@ -35,7 +36,7 @@ func NewRetryableHTTPClient(options ...Option) *http.Client {
35
36
func defaultOptions () httpOpts {
36
37
return httpOpts {
37
38
RetryMax : 5 ,
38
- Logger : log .Log ,
39
+ Logger : retryablehttp . LeveledLogger ( & leveledLogrus { log .Log }) ,
39
40
40
41
RequestLogHook : func (logger retryablehttp.Logger , req * http.Request , attempt int ) {
41
42
if attempt > 0 {
@@ -47,7 +48,7 @@ func defaultOptions() httpOpts {
47
48
48
49
type httpOpts struct {
49
50
HTTPClient * http.Client
50
- Logger interface {}
51
+ Logger retryablehttp. LeveledLogger
51
52
52
53
RetryMax int
53
54
@@ -82,3 +83,33 @@ func WithHTTPClient(client *http.Client) Option {
82
83
opts .HTTPClient = client
83
84
}
84
85
}
86
+
87
+ type leveledLogrus struct {
88
+ * logrus.Entry
89
+ }
90
+
91
+ func (l * leveledLogrus ) fields (keysAndValues ... interface {}) map [string ]interface {} {
92
+ fields := make (map [string ]interface {})
93
+
94
+ for i := 0 ; i < len (keysAndValues )- 1 ; i += 2 {
95
+ fields [keysAndValues [i ].(string )] = keysAndValues [i + 1 ]
96
+ }
97
+
98
+ return fields
99
+ }
100
+
101
+ func (l * leveledLogrus ) Error (msg string , keysAndValues ... interface {}) {
102
+ l .WithFields (l .fields (keysAndValues ... )).Error (msg )
103
+ }
104
+
105
+ func (l * leveledLogrus ) Info (msg string , keysAndValues ... interface {}) {
106
+ l .WithFields (l .fields (keysAndValues ... )).Info (msg )
107
+ }
108
+
109
+ func (l * leveledLogrus ) Debug (msg string , keysAndValues ... interface {}) {
110
+ l .WithFields (l .fields (keysAndValues ... )).Debug (msg )
111
+ }
112
+
113
+ func (l * leveledLogrus ) Warn (msg string , keysAndValues ... interface {}) {
114
+ l .WithFields (l .fields (keysAndValues ... )).Warn (msg )
115
+ }
0 commit comments