Skip to content

serejja/log

 
 

Repository files navigation

Go logging rethinked

Circle CI Build Status Coverage Status Go Report Card

GoDoc

Usage

log.Println("some log") // unconditional log
log.Trace("trace") // log only with `trace` level
log.Tracef("42: %s", "yep") // each method has it's format alternative
log.Debug("debug") // log only with `debug` level and lower
log.Info("info") // log only with `info` level and lower
log.Warning("warn") // log with `warning` level and lower
log.Error("err") // log with `error` and `critical` level
log.Fatal("haha") // log and panic("haha")

Log adds --log-level flag to your program:

// main.go
package main

import (
    "flag"

    "github.com/yanzay/log"
)

func main() {
    flag.Parse()
    log.Info("info")
}
$ go run main.go --help
Usage:
  -log-level string
        Log level: trace|debug|info|warning|error|critical (default "info")

Advanced Usage

Log Level

You can set logging level manually by:

log.Level = log.LevelTrace

Log Writers

DefaultWriter

DefaultWriter is just a small wrapper for log package from stdlib.

AsyncWriter

You can use AsyncWriter to write your logs asynchronously, without blocking you main execution. To use AsyncWriter, just switch it in your code like this:

log.Writer = log.NewAsyncWriter()

Your Own Writer

Also you can use your own log writer:

log.Writer = myWriter // myWriter should implement io.Writer interface

About

Go logging rethinked

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%