Skip to content

Sam-Lane/loki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"}}

About

Loki a Golang logger for humans

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages