Documentation ¶
Overview ¶
Package log is a gauzy wrapper of package github.com/rs/zerolog, referring to package github.com/go-logr/logr.
This design derives from Dave Cheney's blog:
http://dave.cheney.net/2015/11/05/lets-talk-about-logging.
Usage:
SetStdlog(os.Stderr) ctx := NewTraceIDContext(context.TODO(), "traceID_foo") // Timestamp field is existing, and default time location is time.Local, you can change it by SetTimeFieldLocation. Info(ctx).Str("foo", "bar").Msg("test info") // Output: // {"level":"info","time":"2021-01-10T14:15:57+08:00","foo":"bar","message":"test info"}
Index ¶
- Constants
- func Error(ctx context.Context) *kinet.Event
- func FromStackContext(ctx context.Context) error
- func FromTagContext(ctx context.Context) string
- func FromTraceIDContext(ctx context.Context) string
- func FromUserIDContext(ctx context.Context) string
- func Info(ctx context.Context) *kinet.Event
- func MongoWriter(coll *mongo.Collection, buf uint) (io.Writer, error)
- func New(w io.Writer) kinet.Logger
- func NewStackContext(ctx context.Context, stack error) context.Context
- func NewTagContext(ctx context.Context, tag string) context.Context
- func NewTraceIDContext(ctx context.Context, traceID string) context.Context
- func NewUserIDContext(ctx context.Context, userID string) context.Context
- func SetStdlog(writers ...io.Writer)
- func SetTimeFieldFormat(layout string)
- func SetTimeFieldLocation(locName string) error
- func SetTimeFieldName(name string)
- func SetVersion(v string)
Constants ¶
const ( VersionKey = "version" TraceIDKey = "trace_id" UserIDKey = "user_id" TagKey = "tag" StackKey = "stack" )
Variables ¶
This section is empty.
Functions ¶
func FromStackContext ¶
FromStackContext get an error stack from a context, if exists.
func FromTagContext ¶
FromTagContext get a tag from a context, if exists.
func FromTraceIDContext ¶
FromTraceIDContext get a traceID from a context, if exists.
func FromUserIDContext ¶
FromUserIDContext get a userID from a context, if exists.
func MongoWriter ¶
MongoWriter create a mongo writer to log to.
func NewStackContext ¶
NewStackContext wrap a context with an error stack.
func NewTagContext ¶
NewTagContext wrap a context with a tag.
func NewTraceIDContext ¶
NewTraceIDContext wrap a context with a traceID.
func NewUserIDContext ¶
NewUserIDContext wrap a context with a userID.
func SetTimeFieldLocation ¶
Set time field location.
func SetVersion ¶
func SetVersion(v string)
SetVersion set version of the app that using this log package.
Types ¶
This section is empty.