dbg

package
v0.0.0-...-90f0dbf Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package dbg is a println/printf/log-debugging utility library.

import (
    Dbg "github.com/robertkrimen/dbg"
)

dbg, dbgf := Dbg.New()

dbg("Emit some debug stuff", []byte{120, 121, 122, 122, 121}, math.Pi)
# "2013/01/28 16:50:03 Emit some debug stuff [120 121 122 122 121] 3.141592653589793"

dbgf("With a %s formatting %.2f", "little", math.Pi)
# "2013/01/28 16:51:55 With a little formatting (3.14)"

dbgf("%/fatal//A fatal debug statement: should not be here")
# "A fatal debug statement: should not be here"
# ...and then, os.Exit(1)

dbgf("%/panic//Can also panic %s", "this")
# "Can also panic this"
# ...as a panic, equivalent to: panic("Can also panic this")

dbgf("Any %s arguments without a corresponding %%", "extra", "are treated like arguments to dbg()")
# "2013/01/28 17:14:40 Any extra arguments (without a corresponding %) are treated like arguments to dbg()"

dbgf("%d %d", 1, 2, 3, 4, 5)
# "2013/01/28 17:16:32 Another example: 1 2 3 4 5"

dbgf("%@: Include the function name for a little context (via %s)", "%@")
# "2013... github.com/robertkrimen/dbg.TestSynopsis: Include the function name for a little context (via %@)"

By default, dbg uses log (log.Println, log.Printf, log.Panic, etc.) for output. However, you can also provide your own output destination by invoking dbg.New with a customization function:

import (
    "bytes"
    Dbg "github.com/robertkrimen/dbg"
    "os"
)

# dbg to os.Stderr
dbg, dbgf := Dbg.New(func(dbgr *Dbgr) {
    dbgr.SetOutput(os.Stderr)
})

# A slightly contrived example:
var buffer bytes.Buffer
dbg, dbgf := New(func(dbgr *Dbgr) {
    dbgr.SetOutput(&buffer)
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...interface{}) (dbg DbgFunction, dbgf DbgFunction)

New will create and return a pair of debugging functions. You can customize where they output to by passing in an (optional) customization function:

import (
    Dbg "github.com/robertkrimen/dbg"
    "os"
)

# dbg to os.Stderr
dbg, dbgf := Dbg.New(func(dbgr *Dbgr) {
    dbgr.SetOutput(os.Stderr)
})

Types

type DbgFunction

type DbgFunction func(values ...interface{})

type Dbgr

type Dbgr struct {
	// contains filtered or unexported fields
}

func NewDbgr

func NewDbgr() *Dbgr

func (Dbgr) Dbg

func (self Dbgr) Dbg(values ...interface{})

func (Dbgr) DbgDbgf

func (self Dbgr) DbgDbgf() (dbg DbgFunction, dbgf DbgFunction)

func (Dbgr) Dbgf

func (self Dbgr) Dbgf(values ...interface{})

func (*Dbgr) SetOutput

func (self *Dbgr) SetOutput(output interface{})

SetOutput will accept the following as a destination for output:

*log.Logger         Print*/Panic*/Fatal* of the logger
io.Writer           -
nil                 Reset to the default output (os.Stderr)
"log"               Print*/Panic*/Fatal* via the "log" package

Jump to

Keyboard shortcuts

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