Mentioned in Awesome
Go

Readme Card

I have always appreciated the debug logging pattern commonly used within NodeJS projects. As I worked more with go, I wanted to bring that logging pattern to the language.

kemba is a simple logging library that is a reimplementation of the npm debug module in hopes of bringing that capability to the language.

The kemba logger reads the DEBUG and KEMBA environment variables to determine if a log line should be output. The logger outputs to STDERR.

When it is not set, the logger will immediately return, taking no action.

When the value is set (ex. DEBUG=example:*,tool:details and/or KEMBA=plugin:fxn:start), the logger will determine if it should be enabled when instantiated.

The value of these flags can be a simple regex alternative where a wildcard (*) are replaced with .* and all terms are prepended with ^ and appended with $. If a term does not include a wildcard, then an exact match it required.

Example

package main

import (
	"os"

	"github.com/clok/kemba"
)

var (
	k = kemba.New("human")
)

type engineer struct {
	name      string
	email     string
	motto     string
	languages []string
	tools     []string
	favorites []string
}

func main() {
	_ = os.Setenv("DEBUG", "human")

	derek := engineer{
		name:      "Derek Smith",
		email:     "me@clok.sh",
		motto:     "I can do this all day.",
		languages: []string{"go", "node", "javascript", "typescript", "python", "ruby", "perl", "bash"},
		tools:     []string{"docker", "kubernetes", "aws", "gcp"},
		favorites: []string{"hapi", "debug", "lodash", "husky", "urfave/cli", "git-chglog", "jedib0t/go-pretty", "r3labs/diff"},
	}

	k.Log(derek)
	_ = os.Setenv("DEBUG", "")
}