File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -121,25 +121,24 @@ func ClientLogging(lvl zerolog.Level) ClientMiddleware {
121
121
res , err := next .RoundTrip (r )
122
122
elapsed := time .Now ().Sub (start )
123
123
124
- log := zerolog .Ctx (r .Context ())
124
+ evt := zerolog .Ctx (r .Context ()).
125
+ WithLevel (lvl ).
126
+ Str ("method" , r .Method ).
127
+ Str ("path" , r .URL .String ()).
128
+ Dur ("elapsed" , elapsed )
129
+
125
130
if res != nil {
126
- log .WithLevel (lvl ).
127
- Str ("method" , r .Method ).
128
- Str ("path" , r .URL .String ()).
129
- Int ("status" , res .StatusCode ).
131
+ cached := res .Header .Get (httpcache .XFromCache ) != ""
132
+ evt .Int ("status" , res .StatusCode ).
130
133
Int64 ("size" , res .ContentLength ).
131
- Dur ("elapsed" , elapsed ).
132
- Msg ("github_request" )
134
+ Bool ("cached" , cached )
133
135
} else {
134
- log .WithLevel (lvl ).
135
- Str ("method" , r .Method ).
136
- Str ("path" , r .URL .String ()).
137
- Int ("status" , - 1 ).
136
+ evt .Int ("status" , - 1 ).
138
137
Int64 ("size" , - 1 ).
139
- Dur ("elapsed" , elapsed ).
140
- Msg ("github_request" )
138
+ Bool ("cached" , false )
141
139
}
142
140
141
+ evt .Msg ("github_request" )
143
142
return res , err
144
143
})
145
144
}
You can’t perform that action at this time.
0 commit comments