Package list golang-github-go-kit-kit / 95a7937 log /

Tree @95a7937 (Download .tar.gz) @95a7937raw · history · blame

# package log

`package log` provides a minimal interface for structured logging in services.
It may be wrapped to encode conventions, enforce type-safety, etc.
It can be used for both typical application log events, and log-structured data streams.

## Rationale


## Usage

Typical application logging.

import ""

func main() {
	logger := log.NewPrefixLogger(os.Stderr)
	logger.Log("question", "what is the meaning of life?", "answer", 42)

Contextual logging.

func handle(logger log.Logger, req *Request) {
	logger = log.With(logger, "txid", req.TransactionID, "query", req.Query)

	answer, err := process(logger, req.Query)
	if err != nil {
		logger.Log("err", err)

	logger.Log("answer", answer)

Redirect stdlib log to gokit logger.

import (
	stdlog "log"
	kitlog ""

func main() {
	logger := kitlog.NewJSONLogger(os.Stdout)