log

A go logger that focuses on simplicity

Usage

For APIs refer to: https://godoc.org/github.com/mannharleen/log

Use the default logger config

package main
// filename: main.go

import (
	"github.com/mannharleen/log"
)

func main() {
    log.Debug("bug me not!")
    log.Info("this is not an information desk!")
    log.Warn("this is a warning sign")
    log.Error("it's a error! run!")
}

outputs:

2020-02-14 00:32:55.891Z [DEBUG] [main.go:11] bug me not!
2020-02-14 00:32:55.893Z [INFO] [main.go:12] this is not an information desk!
2020-02-14 00:32:55.893Z [WARN] [main.go:13] this is a warning sign
2020-02-14 00:32:55.893Z [ERROR] [main.go:14] it's a error! run!

Use a custom logger config

Use log.Init to configure some useful defaults eg:

  • AppName
  • Timestamp format
  • A static prefix before each message
package main
// filename: main.go

import (
	"github.com/mannharleen/log"
)

func main() {
    log.Init(os.Stdout, log.WriterConfig{TimeFormat: "2006-01-02", AppName: "APPX"})
    log.Debug("bug me not!")
    log.Info("this is not an information desk!")
    log.Warn("this is a warning sign")
    log.Error("it's a error! run!")
}

outputs:

[APPX] 2020-02-14 [DEBUG] [main.go:17] bug me not!
[APPX] 2020-02-14 [INFO] [main.go:18] this is not an information desk!
[APPX] 2020-02-14 [WARN] [main.go:19] this is a warning sign
[APPX] 2020-02-14 [ERROR] [main.go:20] it's a error! run!