Created
May 20, 2021 13:48
-
-
Save r3code/db334ca8bceb6cb99be40c1471562c80 to your computer and use it in GitHub Desktop.
Predefined pairs for go-kit/log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// try https://goplay.space/#P8MtNeGIX69 | |
import ( | |
"os" | |
"github.com/go-kit/kit/log" | |
) | |
func Msg(s string) []interface{} { | |
return []interface{}{ | |
"msg", | |
s, | |
} | |
} | |
func Err(s string) []interface{} { | |
return []interface{}{ | |
"err", | |
s, | |
} | |
} | |
func Pairs(pairs ...[]interface{}) []interface{} { | |
var result []interface{} | |
for _, p := range pairs { | |
p := p | |
result = append(result, p...) | |
} | |
return result | |
} | |
func main() { | |
logger := log.NewLogfmtLogger(os.Stderr) | |
logger = log.With(logger, "method", "main") | |
logger.Log("1") | |
logger.Log("2") | |
logger.Log(Pairs(Msg("test message"), Err("error text"))...) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment