rs / zerolog

Zero Allocation JSON Logger
MIT License
10.33k stars 564 forks source link

how to get Event timestamp in hook Run() ? #679

Open zhujintao opened 2 months ago

zhujintao commented 2 months ago

suggestion is to use the function in the file event.go

func (e *Event) Timestamp() *Event {
    if e == nil {
        return e
    }
    t := TimestampFunc()
    ctx := context.WithValue(e.GetCtx(), "time", t)
    e.Ctx(ctx)
    e.buf = enc.AppendTime(enc.AppendKey(e.buf, TimestampFieldName), t, TimeFieldFormat)
    return e
}