Sam-Lane/loki

Loki a Golang logger for humans

★ 1Forks 0GoGitHub ↗Compare

README

Loki

/lo‧ki/ Finnish for log; to record something.

Go Reference

Getting started

Basic logging

func main() {
    l := "loki"
    log := loki.New()
    log.Info("hello from %s", l)
}
go run main.go
2021/01/01 18:00:00 [INFO] hello from loki

Setting different log levels

func main() {
    log := loki.New()
    log.Set(loki.ERROR)
    log.Debug("this won't appear")
    log.Error("error message")
}
go run main.go
2021/01/01 18:00:00 [ERROR] error message

Writing to a file

func main() {
    log := loki.New()
    log.WriteFile("/var/log/loki.log")
    log.Info("hello /var/log")
}

Logging in JSON format

Loki supports logging directly out as a json string.

func main() {
    log = loki.NewJsonLogger()
    log.Info("some information from your application")
}
go run main.go
{"timestamp":"2021-01-01T18:00:00.000000Z","message":"some information from your application","level":"INFO","caller":{"function":"main.main","line":3,"file":"/path/to/main.go"}}

Contributors

Sam-Lane

Issues