Categorygithub.com/dolab/logger
repositorypackage
1.5.0
Repository: https://github.com/dolab/logger.git
Documentation: pkg.go.dev

# README

logger

CircleCI godoc license

Efficient and simple logger for golang with more features supported.

  • custom log levels
  • custom log tags
  • custom log colors (only worked for *NIX)
  • custom log output and output format
  • structured log

Install

go get -u github.com/dolab/logger

Usage

package main

import "github.com/dolab/logger"

func main() {
    log, _ := logger.New("stdout")
    log.SetLevel(logger.Ldebug)

    // normal
    log.Debug("Hello, logger!")
    log.Infof("Hello, %s!", "logger")

    // create new logger with tags based on log
    taggedLog := log.New("X-REQUEST-ID")
    taggedLog.Debug("Receive HTTP request")
    taggedLog.Warnf("Send response with %d.", 200)
    
    // or use struct log
    textLog := log.NewTextLogger()
    textLog.Str("key", "value").Err(err, true).Error("it's for demo")
}

Output

  • stdout = os.Stdout
  • stderr = os.Stderr
  • null | nil = os.DevNull
  • path/to/file = os.OpenFile("path/to/file", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)

Level

  • Ldebug = DEBUG
  • Linfo = INFO
  • Lwarn = WARN
  • Lerror = ERROR
  • Lfatal = FATAL
  • Lpanic = PANIC
  • Ltrace = Stack

License

MIT

Author

Spring MC