项目作者: jmank88

项目描述 :
error-less go-kit/log extension
高级语言: Go
项目地址: git://github.com/jmank88/mustlog.git
创建时间: 2017-02-28T17:58:03Z
项目社区:https://github.com/jmank88/mustlog

开源协议:MIT License

下载


MustLog GoDoc Go Report Card

An error-less go-kit/log extension.

MustLogger

MustLogger extends log.Logger with Must, an error-less version of Log.

  1. mustLogger := NewMustLogger(&errLogger{}, func(err error, keyvals ...interface{}) {
  2. fmt.Println("failed to log:", err)
  3. })
  4. mustLogger.Log("k", "v")
  5. mustLogger.Log(poison, "poison")
  6. mustLogger.Must("k", "v")
  7. mustLogger.Must(poison, "poison")

Output:

  1. k v
  2. k v
  3. failed to log: poisoned

MustContext

MustContext extends log.Context to implement MustLogger.

  1. mustContext := NewMustContext(&errLogger{}, func(err error, keyvals ...interface{}) {
  2. fmt.Println("failed to log:", err)
  3. })
  4. mustContext.Must("k", "v")
  5. mustContext.Must(poison, "poison")
  6. mustContext = mustContext.With("withK", "withV")
  7. mustContext.Must("k", "v")
  8. mustContext.Must(poison, "poison")
  9. mustContext = mustContext.WithPrefix("prefixK", "prefixV")
  10. mustContext.Must("k", "v")
  11. mustContext.Must(poison, "poison")

Output:

  1. k v
  2. failed to log: poisoned
  3. withK withV k v
  4. failed to log: poisoned
  5. prefixK prefixV withK withV k v
  6. failed to log: poisoned