Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RFC3339Nano as another zapcore.TimeEncoder #659

Open
nattawitc opened this issue Dec 14, 2018 · 1 comment
Open

Add support for RFC3339Nano as another zapcore.TimeEncoder #659

nattawitc opened this issue Dec 14, 2018 · 1 comment

Comments

@nattawitc
Copy link

nattawitc commented Dec 14, 2018

zapcore package has implemented 4 types of TimeEncoder (Epoch, EpochMillis, EpochNanos, and ISO8601). Is it possible to add RFC3339 and RFC3339Nano or any other standard format in go's time package. I've seen this implemented in #276 , but I couldn't find it anymore in the current version.

Another solution is to implement a custom TimeEncoder ourself

func rfc3339TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) { enc.AppendString(t.Format(time.RFC3339Nano)) }

but I'm not sure if it will cause any further issues as TimeEncoder.UnmarshalText does not support custom one.

@NathanZook
Copy link

I'm pretty sure that that is only used for zap.Config#Build. BTW, RFC3339Nano especially is ill-behaved. Here's what I'm using:

func Iso3339CleanTime(t time) string {
        t.UTC().Format("2006-01-02T15:04:05.000000Z")
}

func Iso3339CleanTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
        enc.AppendString(Iso3339CleanTime(t))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants