gdebug

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

README

go-debug

go-debug is a similar library to npm debug package. This module was written mostly for personal consumption and does not offer anywhere near the amount of customization offered by the npm package.

go-debug uses the DEBUG envrionment variable to log data. This envar can contain multiple comma seperated values indicating different namespaces. If a * is used as the value of this envar, it will log all namespaces. If the envar does not have any value set, all logs will be ignored.

General rules to remember when setting the DEBUG environment:

  • Multiple namespaces can be specified with a ,
  • * Will log all
  • TAG Will log tag only
  • !TAG Will not be logged

Example: export DEBUG=APP

debugMe := gdebug.New()
debugMe("some log")
// This will not log

newDebug := debug.New(debug.Config{
    Namespace: "APP",
    Style: []color.Attribute{
        Yellow,
        Bold,
    },
})
newDebug("something", 1, true)
// This will log

Install

go get -u github.com/securisec/go-debug

Documentation

Index

Constants

View Source
const (
	// Red foreground
	Red = color.FgRed
	// Blue Blue foreground
	Blue = color.FgBlue
	// Yellow Yellow foreground
	Yellow = color.FgYellow
	// Green Green foreground
	Green = color.FgGreen
	// Cyan foreground
	Cyan = color.FgCyan
	// Magenta foreground
	Magenta = color.FgMagenta
	// White foreground
	White = color.FgWhite
	// Black foreground
	Black = color.FgBlack
	// Bold text
	Bold = color.Bold
	// Italic text
	Italic = color.Italic
	// Underline text
	Underline = color.Underline
	// BlinkRapid text
	BlinkRapid = color.BlinkRapid
	// BlinkSlow text
	BlinkSlow = color.BlinkSlow
	// BgRed background
	BgRed = color.BgRed
	// BgBlue background
	BgBlue = color.BgBlue
	// BgYellow background
	BgYellow = color.BgYellow
	// BgGreen background
	BgGreen = color.BgGreen
	// BgCyan background
	BgCyan = color.BgCyan
	// BgMagenta background
	BgMagenta = color.BgMagenta
	// BgWhite background
	BgWhite = color.BgWhite
	// BgBlack background
	BgBlack = color.BgBlack
)

Variables

View Source
var ConfigDefault = Config{
	Namespace: "DEBUG",
	Style:     []color.Attribute{color.FgCyan},
	ShowInfo:  false,
	Out:       os.Stderr,
	Pretty:    false,
}

ConfigDefault default config. Sets foreground color to green and shows additional info. DEBUG namespace.

Functions

func New

func New(config ...Config) func(...interface{})

New create a new debug function Example: debugApp := gdebug.New() debugApp("Hello world")

Types

type Config

type Config struct {
	// Namespace Namespace to identify different debug statements
	// Optional. Default: DEBUG
	Namespace string
	// Style Array of styles for debug logging
	// Optional. Default: []color.Attribute{Green}
	Style []color.Attribute
	// ShowInfo Show additional information like file name, line number and function name
	// Optional. Default: false
	ShowInfo bool
	// Out controls where something is being logged.
	// Optional. Default: os.Stderr
	Out io.Writer
	// Pretty print objects
	// Optional. Default: false
	Pretty bool
}

Config debug options

Jump to

Keyboard shortcuts

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