dbg

package
v0.0.0-...-53feb6c Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2016 License: GPL-2.0 Imports: 13 Imported by: 3

Documentation

Overview

Package dbg shows more or less output using different debug-levels. You can use

dbg.Lvl1("Important information")
dbg.Lvl2("Less important information")
dbg.Lvl3("Eventually flooding information")
dbg.Lvl4("Definitively flooding information")
dbg.Lvl5("I hope you never need this")

in your program, then according to the debug-level one or more levels of output will be shown. To set the debug-level, use

dbg.SetDebugVisible(3)

which will show all `Lvl1`, `Lvl2`, and `Lvl3`. If you want to turn on just one output, you can use

dbg.LLvl2("Less important information")

By adding a single 'L' to the method, it *always* gets printed.

You can also add a 'f' to the name and use it like fmt.Printf:

dbg.Lvlf1("Level: %d/%d", now, max)

Additional to that you also have

dbg.Warn("Only a warning")
dbg.Error("This is an error, but continues")
dbg.Panic("Something really went bad - calls panic")
dbg.Fatal("No way to continue - calls os.Exit")

The dbg-package also takes into account the following environment-variables:

DEBUG_LVL // will act like SetDebugVisible
DEBUG_TIME // if 'true' it will print the date and time
DEBUG_COLOR // if 'false' it will not use colors

But for this the function ParseEnv() or AddFlags() has to be called.

Index

Constants

This section is empty.

Variables

View Source
var LinePadding = 3

LinePadding of line-numbers for a nice debug-output - used in the same way as NamePadding

View Source
var NamePadding = 40

NamePadding - the padding of functions to make a nice debug-output - this is automatically updated whenever there are longer functions and kept at that new maximum. If you prefer to have a fixed output and don't remember oversized names, put a negative value in here

View Source
var StaticMsg = ""

StaticMsg - if this variable is set, it will be outputted between the position and the message

View Source
var TestStr = ""

TestStr is only used in testing to redirect output to this string

View Source
var Testing = 0

Testing variable can have multiple values 0 - no testing 1 - put all line-numbers to 0 2 - like 1, but write to TestString instead of stdout

Functions

func AddFlags

func AddFlags()

AddFlags adds the flags and the variables for the debug-control

func AfterTest

func AfterTest(t *testing.T)

AfterTest can be called to wait for leaking goroutines to finish. If they do not finish after a reasonable time (600ms) the test will fail.

Inspired by https://golang.org/src/net/http/main_test.go and https://github.com/coreos/etcd/blob/master/pkg/testutil/leak.go

func DebugVisible

func DebugVisible() int

DebugVisible returns the actual visible debug-level

func ErrFatal

func ErrFatal(err error, msg ...string)

ErrFatal calls dbg.Fatal in the case err != nil

func Error

func Error(args ...interface{})

Error prints the error in a nice red color

func Errorf

func Errorf(f string, args ...interface{})

Errorf is like Error but with a format-string

func Fatal

func Fatal(args ...interface{})

Fatal prints out the fatal message and quits

func Fatalf

func Fatalf(f string, args ...interface{})

Fatalf is like Fatal but with a format-string

func LLvl1

func LLvl1(args ...interface{})

LLvl1 *always* prints

func LLvl2

func LLvl2(args ...interface{})

LLvl2 *always* prints

func LLvl3

func LLvl3(args ...interface{})

LLvl3 *always* prints

func LLvl4

func LLvl4(args ...interface{})

LLvl4 *always* prints

func LLvl5

func LLvl5(args ...interface{})

LLvl5 *always* prints

func LLvlf1

func LLvlf1(f string, args ...interface{})

LLvlf1 *always* prints

func LLvlf2

func LLvlf2(f string, args ...interface{})

LLvlf2 *always* prints

func LLvlf3

func LLvlf3(f string, args ...interface{})

LLvlf3 *always* prints

func LLvlf4

func LLvlf4(f string, args ...interface{})

LLvlf4 *always* prints

func LLvlf5

func LLvlf5(f string, args ...interface{})

LLvlf5 *always* prints

func Lvl1

func Lvl1(args ...interface{})

Lvl1 debug output is informational and always displayed

func Lvl2

func Lvl2(args ...interface{})

Lvl2 is more verbose but doesn't spam the stdout in case there is a big simulation

func Lvl3

func Lvl3(args ...interface{})

Lvl3 gives debug-output that can make it difficult to read for big simulations with more than 100 hosts

func Lvl4

func Lvl4(args ...interface{})

Lvl4 is only good for test-runs with very limited output

func Lvl5

func Lvl5(args ...interface{})

Lvl5 is for big data

func Lvlf1

func Lvlf1(f string, args ...interface{})

Lvlf1 is like Lvl1 but with a format-string

func Lvlf2

func Lvlf2(f string, args ...interface{})

Lvlf2 is like Lvl2 but with a format-string

func Lvlf3

func Lvlf3(f string, args ...interface{})

Lvlf3 is like Lvl3 but with a format-string

func Lvlf4

func Lvlf4(f string, args ...interface{})

Lvlf4 is like Lvl4 but with a format-string

func Lvlf5

func Lvlf5(f string, args ...interface{})

Lvlf5 is like Lvl5 but with a format-string

func MainTest

func MainTest(m *testing.M)

MainTest can be called from TestMain to set up some default variables

func Panic

func Panic(args ...interface{})

Panic prints out the panic message and panics

func Panicf

func Panicf(f string, args ...interface{})

Panicf is like Panic but with a format-string

func ParseEnv

func ParseEnv()

ParseEnv looks at the following environment-variables: - DEBUG_LVL - for the actual debug-lvl - default is 1 - DEBUG_TIME - whether to show the timestamp - default is false - DEBUG_COLOR - whether to color the output - default is true

func Print

func Print(args ...interface{})

Print directly sends the arguments to the stdout

func Printf

func Printf(f string, args ...interface{})

Printf is like Print but takes a formatting-argument first

func SetDebugVisible

func SetDebugVisible(lvl int)

SetDebugVisible set the global debug output level in a go-rountine-safe way

func SetShowTime

func SetShowTime(show bool)

SetShowTime allows for turning on the flag that adds the current time to the debug-output

func SetUseColors

func SetUseColors(show bool)

SetUseColors can turn off or turn on the use of colors in the debug-output

func ShowTime

func ShowTime() bool

ShowTime returns the current setting for showing the time in the debug output

func Stack

func Stack() string

Stack converts []byte to string

func TestFatal

func TestFatal(t *testing.T, err error, msg ...string)

TestFatal calls t.Fatal in the case err != nil

func TestOutput

func TestOutput(show bool, level int)

TestOutput sets the DebugVisible to 0 if 'show' is false, else it will set DebugVisible to 'level'

Usage: TestOutput( test.Verbose(), 2 )

func UseColors

func UseColors() bool

UseColors returns the actual setting of the color-usage in dbg

func Warn

func Warn(args ...interface{})

Warn prints out the warning

func Warnf

func Warnf(f string, args ...interface{})

Warnf is like Warn but with a format-string

Types

This section is empty.

Jump to

Keyboard shortcuts

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