Giter Club home page Giter Club logo

kemba's Introduction

kemba

License: MIT Go Report Card Coverage Status go.dev reference Mentioned in Awesome Go

debug logging tool inspired by https://github.com/visionmedia/debug

Why is it named kemba?

debug is more generally considered to be runtime/debug within Go. Since this takes heavy inspiration from my experiences using the npm module debug I wanted to find a word that was somewhat connected to the inspiration. According to Google translate "debug" in English translated to Icelandic results in "kemba".

Usage

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 of a wildcard in the middle of a tag string: DEBUG=example:*:fxn will match tags like [example:tag1:fxn, example:tag2:fxn, example:anything:fxn, ...]

To disabled colors, set the NOCOLOR environment variable to any value.

image

package main

import (
    "time"

	"github.com/clok/kemba"
)

type myType struct {
	a, b int
}

// When the DEBUG or KEMBA environment variable is set to DEBUG=example:* the kemba logger will output to STDERR
func main () {
    k := kemba.New("example:tag")
	
    var x = []myType{
    	{1, 2},
    	{3, 4},
    }
    k.Printf("%#v", x)
    // Output to os.Stderr
    // example:tag []main.myType{main.myType{a:1, b:2}, main.myType{a:3, b:4}} +0s

    // Artificial delay to demonstrate the time tagging
    time.Sleep(250 * time.Millisecond)
    k.Printf("%# v", x)
    k.Println(x)

    // Artificial delay to demonstrate the time tagging
    time.Sleep(100 * time.Millisecond)
    k.Log(x)
    // All result in the same output to os.Stderr
    // example:tag []main.myType{ +XXms
    // example:tag     {a:1, b:2},
    // example:tag     {a:3, b:4},
    // example:tag }

    // Create a new logger with an extended tag
    k1 := k.Extend("1")
    k1.Println("a string", 12, true)
    // Output to os.Stderr
    // example:tag:1 a string +0s
    // example:tag:1 int(12)
    // example:tag:1 bool(true)
}

Development

  1. Fork the clok/kemba repo
  2. Use go >= 1.16
  3. Branch & Code
  4. Run linters ๐Ÿงน golangci-lint run
  5. Commit with a Conventional Commit
  6. Open a PR

kemba's People

Contributors

clok avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kemba's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: .github/renovate.json
Error type: Invalid JSON (parsing failed)
Message: Syntax error near ", ],

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/lint.yml
  • actions/checkout v4
  • golangci/golangci-lint-action v3
  • ubuntu 22.04
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-go v5
  • goreleaser/goreleaser-action v5
  • ubuntu 22.04
.github/workflows/test.yml
  • actions/setup-go v5
  • actions/checkout v4
  • jandelgado/gcov2lcov-action v1.0.9
  • coverallsapp/github-action v2.2.3
  • ubuntu 22.04
.github/workflows/warm.yaml
  • ubuntu 22.04
gomod
go.mod
  • go 1.16
  • github.com/gookit/color v1.5.4
  • github.com/kr/pretty v0.3.1
  • github.com/stretchr/testify v1.8.4

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.