@@ -87,6 +87,11 @@ func TestToLoggerWithOptionals(t *testing.T) {
87
87
if strings .Contains (str .String (), expectedCompletedResults ) == false {
88
88
t .Errorf ("Expected output was incorrect, %s does not contain new line" , str .String ())
89
89
}
90
+
91
+ notExpectedDurationResults := fmt .Sprintf (`Completed %d in` , http .StatusOK )
92
+ if strings .Contains (str .String (), notExpectedDurationResults ) == true {
93
+ t .Errorf ("Expected output was incorrect, %s should not contain %s" , str .String (), notExpectedDurationResults )
94
+ }
90
95
}
91
96
92
97
func TestToString (t * testing.T ) {
@@ -160,6 +165,11 @@ func TestToStringWithOptionals(t *testing.T) {
160
165
if strings .Contains (str .String (), expectedStartedResults ) == false {
161
166
t .Errorf ("Expected output was incorrect, %s does not contain %s" , str .String (), expectedStartedResults )
162
167
}
168
+
169
+ notExpectedDurationResults := fmt .Sprintf (`Completed %d in` , http .StatusOK )
170
+ if strings .Contains (str .String (), notExpectedDurationResults ) == true {
171
+ t .Errorf ("Expected output was incorrect, %s should not contain %s" , str .String (), notExpectedDurationResults )
172
+ }
163
173
}
164
174
165
175
// Helpers
@@ -185,14 +195,14 @@ func (app *application) logRequestToString(next http.Handler) http.Handler {
185
195
186
196
func (app * application ) logRequestToLoggerWithOptionals (next http.Handler ) http.Handler {
187
197
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
188
- lr := LogRequest {Request : r , Writer : w , Handler : next , NewLine : 1 , Timestamp : true }
198
+ lr := LogRequest {Request : r , Writer : w , Handler : next , NewLine : 1 , Timestamp : true , HideDuration : true }
189
199
lr .ToLogger (app .infoLog )
190
200
})
191
201
}
192
202
193
203
func (app * application ) logRequestToStringWithOptionals (next http.Handler ) http.Handler {
194
204
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
195
- lr := LogRequest {Request : r , Writer : w , Handler : next , Timestamp : true }
205
+ lr := LogRequest {Request : r , Writer : w , Handler : next , Timestamp : true , HideDuration : true }
196
206
app .infoLog .Println (lr .ToString ()["started" ])
197
207
app .infoLog .Println (lr .ToString ()["completed" ])
198
208
})
0 commit comments