dbg

package module
v0.0.0-...-df2759e Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: Unlicense Imports: 7 Imported by: 17

README

dbg

A collection of debugging and tracking routines and some other convenience functions

Color()					Enable colored text output (if system supports it)
NoColor()				Disable colored text output

Panic( "fmtStr", [chk_args] )		output colored text then PANIC! -- See dbg.Panic below
Fatal( "fmtStr", [chk_args] )		output colored text then force exit
PanicIf( bool, "fmtStr", [chk_args] )	PANIC only if true -- See dbg.Panic below
FatalIf( bool, "fmtStr", [chk_args] )	force exit if true
PanicIfErr( err, "fmtStr", [chk_args] )	PANIC only if err is not nil -- See dbg.Panic below
FatalIfErr( err, "fmtStr", [chk_args] )	force exit if err is not nil

SetLevel( int )				set the current debug output level
SetMask( int )				set the current debug output bit mask

LvlMsg( int, "fmtStr", [fmt_args] )
	output message if int val <= current debug level

MaskMsg( int, "fmtStr", [fmt_args] )
	output message if val masks out as any non-zero value

ChkTru( bool, [chk_args] ) bool
	if test value is false, output check failed message (see below)
	 returns TRUE on failure allowing this to be wrapped as part of 'if'

ChkTru[PX]( bool, [chk_args] )
	if test value is false, output check failed message (see below)
	 then can either Panic or force Exit -- See dbg.Panic below

ChkErr( error, [chk_args] ) bool
	if error non-nil, output check failed message (see below)
	 returns TRUE on non-nil allowing this to be wrapped as part of 'if'

ChkErr[PX]( error, [chk_args] )
	if error non-nil, output check failed message (see below) then
	 either Panic or force Exit -- See dbg.Panic below

ChkErrI( error, []error, [chk_args]) bool
	if error non-nil, output check failed message (see below) as long
	 as it's not in the ignore list of errors
	 returns TRUE on non-nil allowing this to be wrapped as part of 'if'

TRC( [trc_args] )		output calling func file & line number followed by any arg data
TRCIF( tst [, trc_args] )	conditional TRC
TRCFROM( [trc_args] )		output func calling func file & line number followed by any arg data

Trace()				output call stack (up to ten levels deep)

Echo( "fmtStr", [fmt_args] )	output normal text (quick way to do output w/o 'fmt' if you want)
Note( "fmtStr", [fmt_args] )	output colored text
Info( "fmtStr", [fmt_args] )	output colored text
Message( "fmtStr", [fmt_args] )	output colored text
Warning( "fmtStr", [fmt_args] )	output colored text
Error( "fmtStr", [fmt_args] )	output colored text
Danger( "fmtStr", [fmt_args] )	output colored text

Different argument options:

args:			arguments for fmt.Printf format staring
chk_args:		["fmtStr", [args]], [CLOSER()]
			 any CLOSER() func is called before doing
			 any panic or exit for a failure case
trc_args:		[error] | ["fmtStr", [args]]

dbg.Panic() always passes the built-in panic a STRING, even if given an error If using defer, the returned value for 'recover' will therefore always be a string

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CAUTION

func CAUTION(fstr string, a ...interface{})

black on yellow (bright orange) text to output

func Caution

func Caution(fstr string, a ...interface{})

yellow (bright orange) text to output

func ChkErr

func ChkErr(e error, a ...interface{}) bool

output err message if given error isn't nil - returns testable boolean

func ChkErrI

func ChkErrI(e error, i []error, a ...interface{}) bool

output err message if error, but ignore (don't output) any in the 'i' slice

func ChkErrList

func ChkErrList(errs []error, a ...interface{}) bool

output err message if there are any errors in the given list

func ChkErrP

func ChkErrP(e error, a ...interface{})

output err message and PANIC if given error isn't nil

func ChkErrX

func ChkErrX(e error, a ...interface{})

output err message and EXIT if given error isn't nil

func ChkTru

func ChkTru(tst bool, a ...interface{}) bool

output err message if test not true

func ChkTruP

func ChkTruP(tst bool, a ...interface{})

output err message if test not true, then PANIC

func ChkTruX

func ChkTruX(tst bool, a ...interface{})

output err message if test not true, then EXIT

func Color

func Color()

enable color output for debug text

func Danger

func Danger(fstr string, a ...interface{})

bold white on red background text to output

func ERROR

func ERROR(fstr string, a ...interface{})

red text to output

func Echo

func Echo(fstr string, a ...interface{})

simply echo to output, no color hilites

func ErrAt

func ErrAt() (string, int)

return the callers location information (file & line#)

func ErrWasAt

func ErrWasAt() (string, int)

return the callers caller location information (file & line#)

func Error

func Error(fstr string, a ...interface{})

red text to output

func ExpErr

func ExpErr(e, x error) bool

output err message if expected error not matched

func FAULT

func FAULT(fstr string, a ...interface{})

red text to output

func Failed

func Failed(fstr string, a ...interface{})

magenta text to output

func Fatal

func Fatal(a ...interface{})

fatal error (exit) with any optional chk_args

func FatalIf

func FatalIf(b bool, a ...interface{})

conditional fatal

func FatalIfErr

func FatalIfErr(e error, a ...interface{})

conditional fatal

func IAm

func IAm() string

return the callers func name

func IWas

func IWas() string

func ImAt

func ImAt() string

a quick func to output location information (file & line#)

func Info

func Info(fstr string, a ...interface{})

green text to output

func Link()

dummy func to allow external use / non-use

have dbg.Link() at start of file and you can enable / disable dbg code
without getting the pesky build errors for import use of non-use
-- should remove after any debug along with the import

func Message

func Message(fstr string, a ...interface{})

cyan text to output

func MustHave

func MustHave(a ...interface{}) error

func MustHaveP

func MustHaveP(a ...interface{})

func NoColor

func NoColor()

disable color output for debug text

func Note

func Note(fstr string, a ...interface{})

blue text to output

func Panic

func Panic(a ...interface{})

panic with any optional chk_args

func PanicIf

func PanicIf(b bool, a ...interface{})

conditional panic

func PanicIfErr

func PanicIfErr(e error, a ...interface{})

conditional panic

func StackTrace

func StackTrace()

output a stack trace to aid in debugging

func Status

func Status(fstr string, a ...interface{})

gray text to output

func TRC

func TRC(a ...interface{})

a quick 'I am here' function for debugging & tracking, takes optional trc_args

func TRCFROM

func TRCFROM(a ...interface{})

a quick 'I came from' function for debugging & tracking, takes optional trc_args

func TRCIF

func TRCIF(b bool, a ...interface{})

a quick conditional 'I am here' function for debugging & tracking, takes optional trc_args

Remove because we now have (b Dbg) TRC?

func WARNING

func WARNING(fstr string, a ...interface{})

white on orange text to output

func Warning

func Warning(fstr string, a ...interface{})

orange text to output

func WasAt

func WasAt() string

a quick func to output location information (file & line#)

Types

type Dbg

type Dbg struct {
	Enabled bool
	MaxOut  int // maximum number of lines to output before doing system exit (0==unlimited)
}

Debug output that can work off of a simple bool flag

func (*Dbg) Caution

func (d *Dbg) Caution(fstr string, a ...interface{})

yellow (bright orange) text to output

func (*Dbg) ChkErr

func (d *Dbg) ChkErr(e error, a ...interface{}) bool

output err message if given error isn't nil - returns testable boolean

func (*Dbg) ChkErrI

func (d *Dbg) ChkErrI(e error, i []error, a ...interface{}) bool

output err message if error, but ignore (don't output) any in the 'i' slice

func (*Dbg) ChkTru

func (d *Dbg) ChkTru(tst bool, a ...interface{}) bool

output err message if test not true

func (*Dbg) Danger

func (d *Dbg) Danger(fstr string, a ...interface{})

bold white on red background text to output

func (*Dbg) Echo

func (d *Dbg) Echo(fstr string, a ...interface{})

simply echo to output, no color hilites

func (*Dbg) Error

func (d *Dbg) Error(fstr string, a ...interface{})

red text to output

func (*Dbg) Failed

func (d *Dbg) Failed(fstr string, a ...interface{})

magenta text to output

func (*Dbg) Info

func (d *Dbg) Info(fstr string, a ...interface{})

green text to output

func (*Dbg) Message

func (d *Dbg) Message(fstr string, a ...interface{})

cyan text to output

func (*Dbg) Note

func (d *Dbg) Note(fstr string, a ...interface{})

blue text to output

func (*Dbg) Status

func (d *Dbg) Status(fstr string, a ...interface{})

gray text to output

func (Dbg) TRC

func (d Dbg) TRC(a ...interface{})

use Dbg interface for TRC

func (Dbg) TRCFROM

func (d Dbg) TRCFROM(a ...interface{})

use Dbg interface for TRCFROM

func (*Dbg) Warning

func (d *Dbg) Warning(fstr string, a ...interface{})

orange text to output

type DbgLvl

type DbgLvl struct {
	Level int
}

Debug output that can work off of an output level:

		In general, the higher the DbgLvl, the more output
	if DbgLvl == 0, all output is disabled
 if DbgLvl < level, output is disabled

func (DbgLvl) Caution

func (d DbgLvl) Caution(l int, fstr string, a ...interface{})

yellow (bright orange) text to output

func (DbgLvl) ChkErr

func (d DbgLvl) ChkErr(l int, e error, a ...interface{}) bool

output err message if given error isn't nil - returns testable boolean

func (DbgLvl) ChkTru

func (d DbgLvl) ChkTru(l int, tst bool, a ...interface{}) bool

output err message if test not true

func (DbgLvl) Danger

func (d DbgLvl) Danger(l int, fstr string, a ...interface{})

bold white on red background text to output

func (DbgLvl) Echo

func (d DbgLvl) Echo(l int, fstr string, a ...interface{})

simply echo to output, no color hilites

func (DbgLvl) Error

func (d DbgLvl) Error(l int, fstr string, a ...interface{})

red text to output

func (DbgLvl) Failed

func (d DbgLvl) Failed(l int, fstr string, a ...interface{})

magenta text to output

func (DbgLvl) Info

func (d DbgLvl) Info(l int, fstr string, a ...interface{})

green text to output

func (DbgLvl) Message

func (d DbgLvl) Message(l int, fstr string, a ...interface{})

cyan text to output

func (DbgLvl) Note

func (d DbgLvl) Note(l int, fstr string, a ...interface{})

blue text to output

func (DbgLvl) Status

func (d DbgLvl) Status(l int, fstr string, a ...interface{})

stat text to output

func (DbgLvl) Warning

func (d DbgLvl) Warning(l int, fstr string, a ...interface{})

orange text to output

type DbgMsk

type DbgMsk struct {
	Mask uint32
}

Debug output that can work off of an output mask:

if DbgMsk & mask == 0, output is disabled

func (DbgMsk) Caution

func (d DbgMsk) Caution(m uint32, fstr string, a ...interface{})

yellow (bright orange) text to output

func (DbgMsk) ChkErr

func (d DbgMsk) ChkErr(m uint32, l int, e error, a ...interface{}) bool

output err message if given error isn't nil - returns testable boolean

func (DbgMsk) ChkTru

func (d DbgMsk) ChkTru(m uint32, l int, tst bool, a ...interface{}) bool

output err message if test not true

func (DbgMsk) Danger

func (d DbgMsk) Danger(m uint32, fstr string, a ...interface{})

bold white on red background text to output

func (DbgMsk) Echo

func (d DbgMsk) Echo(m uint32, fstr string, a ...interface{})

simply echo to output, no color hilites

func (DbgMsk) Error

func (d DbgMsk) Error(m uint32, fstr string, a ...interface{})

red text to output

func (DbgMsk) Failed

func (d DbgMsk) Failed(m uint32, fstr string, a ...interface{})

magenta text to output

func (DbgMsk) Info

func (d DbgMsk) Info(m uint32, fstr string, a ...interface{})

green text to output

func (DbgMsk) Message

func (d DbgMsk) Message(m uint32, fstr string, a ...interface{})

cyan text to output

func (DbgMsk) Note

func (d DbgMsk) Note(m uint32, fstr string, a ...interface{})

blue text to output

func (DbgMsk) Status

func (d DbgMsk) Status(m uint32, fstr string, a ...interface{})

gray text to output

func (DbgMsk) Warning

func (d DbgMsk) Warning(m uint32, fstr string, a ...interface{})

orange text to output

Jump to

Keyboard shortcuts

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