import ( "os" "fmt" "github.com/go-kit/kit/log" ) func main() { logger := log.NewLogfmtLogger(os.Stderr) // creates a new logger instance with Logfmt format and STDERR output logger.Log("msg", "Hello world") // logs a message with "msg" key and "Hello world" value }
import ( "os" "fmt" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" ) func main() { logger := log.NewLogfmtLogger(os.Stderr) level.Info(logger).Log("msg", "Starting app", "port", 8080) // logs an info message with "msg" and "port" fields level.Warn(logger).Log("msg", "Database connection lost") // logs a warning message with "msg" field level.Error(logger).Log("msg", "Internal server error", "err", fmt.Errorf("'%s' failed", "foo()")) // logs an error message with "msg" and "err" fields }In these examples, we can see how to create a new logger instance with a specific format and output, and how to use the different log levels and fields to write messages with relevant information. The level package is part of the go-kit.kit.log library and provides a fluent interface to set the log level and write messages with fields.