| 37 | ) |
| 38 | |
| 39 | func TestEncodeTimePrecisionToMicroSeconds(t *testing.T) { |
| 40 | buf := bytes.NewBuffer(nil) |
| 41 | syncer := zapcore.AddSync(buf) |
| 42 | zc := zapcore.NewCore( |
| 43 | zapcore.NewJSONEncoder(DefaultZapLoggerConfig.EncoderConfig), |
| 44 | syncer, |
| 45 | zap.NewAtomicLevelAt(zap.InfoLevel), |
| 46 | ) |
| 47 | |
| 48 | lg := zap.New(zc) |
| 49 | lg.Info("TestZapLog") |
| 50 | fields := commonLogFields{} |
| 51 | require.NoError(t, json.Unmarshal(buf.Bytes(), &fields)) |
| 52 | // example 1: 2024-06-06T23:37:21.948385Z |
| 53 | // example 2 with zone offset: 2024-06-06T16:16:44.176778-0700 |
| 54 | regex := `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.(\d+)(Z|[+-]\d{4})` |
| 55 | re := regexp.MustCompile(regex) |
| 56 | matches := re.FindStringSubmatch(fields.Timestamp) |
| 57 | require.Len(t, matches, 3) |
| 58 | require.Lenf(t, matches[1], fractionSecondsPrecision, "unexpected timestamp %s", fields.Timestamp) |
| 59 | } |
| 60 | |
| 61 | func TestMergeOutputPaths(t *testing.T) { |
| 62 | tests := []struct { |