https://github.com/jmank88/mustlog
error-less go-kit/log extension
https://github.com/jmank88/mustlog
go go-kit golang logging
Last synced: about 1 month ago
JSON representation
error-less go-kit/log extension
- Host: GitHub
- URL: https://github.com/jmank88/mustlog
- Owner: jmank88
- License: mit
- Created: 2017-02-28T17:58:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-19T17:41:24.000Z (over 8 years ago)
- Last Synced: 2025-04-03T13:27:36.590Z (6 months ago)
- Topics: go, go-kit, golang, logging
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MustLog [](https://godoc.org/github.com/jmank88/mustlog) [](https://goreportcard.com/report/github.com/jmank88/mustlog)
An error-less go-kit/log extension.## MustLogger
MustLogger extends log.Logger with Must, an error-less version of Log.
```go
mustLogger := NewMustLogger(&errLogger{}, func(err error, keyvals ...interface{}) {
fmt.Println("failed to log:", err)
})
mustLogger.Log("k", "v")
mustLogger.Log(poison, "poison")mustLogger.Must("k", "v")
mustLogger.Must(poison, "poison")
```Output:
```text
k v
k v
failed to log: poisoned
```## MustContext
MustContext extends log.Context to implement MustLogger.
```go
mustContext := NewMustContext(&errLogger{}, func(err error, keyvals ...interface{}) {
fmt.Println("failed to log:", err)
})mustContext.Must("k", "v")
mustContext.Must(poison, "poison")mustContext = mustContext.With("withK", "withV")
mustContext.Must("k", "v")
mustContext.Must(poison, "poison")mustContext = mustContext.WithPrefix("prefixK", "prefixV")
mustContext.Must("k", "v")
mustContext.Must(poison, "poison")
```Output:
```text
k v
failed to log: poisoned
withK withV k v
failed to log: poisoned
prefixK prefixV withK withV k v
failed to log: poisoned
```