Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 1.09 KB

README.md

File metadata and controls

45 lines (31 loc) · 1.09 KB

golog

A simple logger for go.

Install

go get github.com/kibaamor/golog

Example

example.go

// basic logger
logger := golog.NewTermLogger(os.Stderr, true)

// got: `[INFO] 1:1 k1:v1 k2:[1 1]`
logger.Log(golog.LevelInfo, 1, 1, "k1", "v1", "k2", []int{1, 1})

// combine multiple logger
// Discard is logger with discard everything
logger = golog.MultiLogger(logger, golog.Discard)

// got: `[INFO] 1:1 k1:v1 k2:[1 1]`
logger.Log(golog.LevelInfo, 1, 1, "k1", "v1", "k2", []int{1, 1})

// filter with log level
logger = golog.WithFilter(logger, golog.FilterLevel(golog.LevelWarn))
// got: ``
logger.Log(golog.LevelInfo, 1, 1)

// auto add timestamp and caller information
logger = golog.WithHandler(logger, golog.HandlerDefaultTimestamp, golog.HandlerDefaultCaller)

// got:`[2022-10-28T16:37:50.786+08:00][example.go:33][WARN] 1:1`
logger.Log(golog.LevelWarn, 1, 1)

// Helper provides useful apis, such as Info, Infow.
helper := golog.NewHelper(logger)

// got: `[2022-10-28T16:37:50.786+08:00][example.go:39][ERROR] golog: hi`
helper.Errorf("golog: %v", "hi")