debugger

package module
v0.0.0-...-4dcc993 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2014 License: MIT Imports: 7 Imported by: 0

README

go-debug

GoDoc

debugger provides an environment based debugger in code.

Based heavily on visionmedia's debug.

Install

$ go get github.com/swhite24/go-debug

Usage

debugger will output logs based on the DEBUG environment variable. DEBUG may be comma-separated to provide multiple values, each of which may contain a wildcard *. If the provided key does not contain a match in the environment, no output will be displayed.

For instance, the following script:

package main

import (
	"time"
    "github.com/swhite24/go-debug"
)

func main () {
    hello := debugger.NewDebugger("hello")
    world := debugger.NewDebugger("world")
    foo := debugger.NewDebugger("foo")

    hello.Log("Log from hello")
    world.Log("Log from world")
    foo.Log("Log from foo")

	time.Sleep(time.Duration(1) * time.Second)
	hello.Log("Log from hello after 1 sec")
}

when run with the command DEBUG=hel*,world go run test.go will output the following:

Note the use of wildcards and the omission of logs from the "foo" debugger.

Documentation

Overview

package debugger provides an environment based logger

In order for logs to display, the DEBUG environment variable must be set and match the key provided to debugger.NewDebugger

DEBUG may be set as a comma-separated list, and also supports wildcards matching (*).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Debugger

type Debugger interface {

	// Log will output log message to stdout, prefixed with key
	Log(vals ...interface{})
}

Debugger provides logging based on DEBUG environment variable

If the provided debugger key is found to be a match for the environment, logs will be displayed.

func NewDebugger

func NewDebugger(key string) Debugger

NewDebugger provides creates a new Debugger based the provided key. Each debugger will be assigned a different color, up to five colors, then repeat.

key will be compared with the environment variable "DEBUG" in order to determine if logs should be output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL