(t *testing.T)
| 211 | } |
| 212 | |
| 213 | func Test_CtxLogger(t *testing.T) { |
| 214 | initDefaultLogger() |
| 215 | |
| 216 | var w byteSliceWriter |
| 217 | SetOutput(&w) |
| 218 | |
| 219 | ctx := context.Background() |
| 220 | |
| 221 | WithContext(ctx).Tracef("trace %s", work) |
| 222 | WithContext(ctx).Debugf("received %s order", work) |
| 223 | WithContext(ctx).Infof("starting %s", work) |
| 224 | WithContext(ctx).Warnf("%s may fail", work) |
| 225 | WithContext(ctx).Errorf("%s failed %d", work, 50) |
| 226 | |
| 227 | require.Panics(t, func() { |
| 228 | WithContext(ctx).Panicf("%s panic", work) |
| 229 | }) |
| 230 | |
| 231 | require.Equal(t, "[Trace] trace work\n"+ |
| 232 | "[Debug] received work order\n"+ |
| 233 | "[Info] starting work\n"+ |
| 234 | "[Warn] work may fail\n"+ |
| 235 | "[Error] work failed 50\n"+ |
| 236 | "[Panic] work panic\n", string(w.b)) |
| 237 | } |
| 238 | |
| 239 | // Test_WithContextTemplate runs serially because initDefaultLogger, |
| 240 | // SetContextTemplate, MustSetContextTemplate, and SetOutput mutate package |
nothing calls this directly
no test coverage detected