Skip to content

Commit

Permalink
add: zlog fields func
Browse files Browse the repository at this point in the history
  • Loading branch information
moocss committed Nov 6, 2024
1 parent 71b6a7a commit 9f1e49d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions log/zlog/fields.go
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
package zlog

import (
"time"

"go.uber.org/zap"
)

// TimeValue returns a Value for a time.Time.
// It discards the monotonic portion.
func TimeValue(v time.Time) any {
return uint64(v.UnixNano())
}

// DurationValue returns a Value for a time.Duration.
func DurationValue(v time.Duration) uint64 {
return uint64(v.Nanoseconds())
}

func Err(err error) Field {
return zap.Error(err)
}

func String(key, v string) Field {
return zap.String(key, v)
}

func Uint64(key string, v uint64) Field {
return zap.Uint64(key, v)
}

func Int64(key string, v int64) Field {
return zap.Int64(key, v)
}

func Float64(key string, v float64) Field {
return zap.Float64(key, v)
}

func Bool(key string, b bool) Field {
return zap.Bool(key, b)
}

func Int(key string, v int) Field {
return Int64(key, int64(v))
}

func Any(key string, v any) Field {
return zap.Any(key, v)
}

func Time(key string, v time.Time) Field {
return zap.Time(key, v)
}

func Duration(key string, v time.Duration) Field {
return zap.Duration(key, v)
}

0 comments on commit 9f1e49d

Please sign in to comment.