debug

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 6 Imported by: 0

README

A debug module for Go

Package debug implements the missing debug printing function for Go.

The debug messages printed include filename, line number, package and name of the calling function, and they are printed in color so they stand out in the console terminal. Colorization is auto-disabled when output is redirected to a file or piped to another program.

Despite being just a souped-up printf, I wouldn't want to do without this package. Take it, as a convenience to ease your life in software dev.

Usage

Step 1. Import the package.

		import "github.com/walterdejong/debug"

Step 2. Enable debug mode. Additionally, you may configure the colors and/or the output file handle.

		debug.Enabled = true

		// change colorization (if we want to)
		debug.Info = debug.DarkCyan
		debug.Message = debug.Cyan

		// change output to stdout (default is stderr)
		debug.SetOutput(os.Stdout)

Step 3. Log messages. Debug() works just like fmt.Printf().

		debug.Debug("the value of x == %#v", x)

This produces output like:

    % file.go:42 pkg.MyFunction() the value of x == []int{1, 2, 3}

See also the provided example program.

Copyright (c) 2025 by Walter de Jong [email protected]

This software is freely available under terms described in the MIT license.

Documentation

Overview

Package debug implements debug printing functionality.

Index

Constants

View Source
const (
	Reset       string = "\x1b[0m"
	DarkGray           = "\x1b[30;1m"
	Red         string = "\x1b[31;1m"
	Green       string = "\x1b[32;1m"
	Yellow      string = "\x1b[33;1m"
	Blue        string = "\x1b[34;1m"
	Magenta     string = "\x1b[35;1m"
	Cyan        string = "\x1b[36;1m"
	White       string = "\x1b[37;1m"
	Black              = "\x1b[30m"
	DarkRed     string = "\x1b[31m"
	DarkGreen   string = "\x1b[32m"
	DarkYellow  string = "\x1b[33m"
	DarkBlue    string = "\x1b[34m"
	DarkMagenta string = "\x1b[35m"
	DarkCyan    string = "\x1b[36m"
	Gray        string = "\x1b[37m"
)

debug color codes.

Variables

View Source
var (
	Enabled      bool        // set this to true to enable debug output
	Colorize     bool        // will be set to true if on a tty terminal
	ColorInfo    = DarkGreen // color of the informational lead
	ColorMessage = Reset     // color of the message. Default is no color
	ColorReset   = Reset     // reset the color back to normal after printing the message

)

Functions

func Debug

func Debug(format string, a ...any)

Debug prints debug message (if debug output is enabled). A newline is automatically appended.

func SetOutput

func SetOutput(f *os.File)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳