log

package
v0.0.0-...-2ef61a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2021 License: MIT Imports: 8 Imported by: 1

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

View Source
const (
	VersionKey = "version"
	TraceIDKey = "trace_id"
	UserIDKey  = "user_id"
	TagKey     = "tag"
	StackKey   = "stack"
)

Variables

This section is empty.

Functions

func Error

func Error(ctx context.Context) *kinet.Event

Error return log event of error level created by default logger.

func FromStackContext

func FromStackContext(ctx context.Context) error

FromStackContext get an error stack from a context, if exists.

func FromTagContext

func FromTagContext(ctx context.Context) string

FromTagContext get a tag from a context, if exists.

func FromTraceIDContext

func FromTraceIDContext(ctx context.Context) string

FromTraceIDContext get a traceID from a context, if exists.

func FromUserIDContext

func FromUserIDContext(ctx context.Context) string

FromUserIDContext get a userID from a context, if exists.

func Info

func Info(ctx context.Context) *kinet.Event

Info return log event of info level created by default logger.

func MongoWriter

func MongoWriter(coll *mongo.Collection, buf uint) (io.Writer, error)

MongoWriter create a mongo writer to log to.

func New

func New(w io.Writer) kinet.Logger

New create a new logger.

func NewStackContext

func NewStackContext(ctx context.Context, stack error) context.Context

NewStackContext wrap a context with an error stack.

func NewTagContext

func NewTagContext(ctx context.Context, tag string) context.Context

NewTagContext wrap a context with a tag.

func NewTraceIDContext

func NewTraceIDContext(ctx context.Context, traceID string) context.Context

NewTraceIDContext wrap a context with a traceID.

func NewUserIDContext

func NewUserIDContext(ctx context.Context, userID string) context.Context

NewUserIDContext wrap a context with a userID.

func SetStdlog

func SetStdlog(writers ...io.Writer)

SetStdlog set the writers of default logger.

func SetTimeFieldFormat

func SetTimeFieldFormat(layout string)

Set time field format.

func SetTimeFieldLocation

func SetTimeFieldLocation(locName string) error

Set time field location.

func SetTimeFieldName

func SetTimeFieldName(name string)

Set time field name.

func SetVersion

func SetVersion(v string)

SetVersion set version of the app that using this log package.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL