debug

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: MIT Imports: 9 Imported by: 0

README

Debug

License Go Reference Go Report Card GitHub CI codecov

Like Rust's dbg macro, but for Go!

Project Description

debug provides a simple, elegant mechanism to streamline "print debugging", inspired by Rust's dbg macro

[!WARNING] This is not intended for logging in production, more to enable quick local debugging while iterating. debug.Debug should not make it into your production code

Installation

go get github.com/FollowTheProcess/debug@latest

Quickstart

Before
package main

import "fmt"

func main() {
    something := "hello"
    fmt.Printf("something = %s\n", something)
}
something = something
  • Not ideal, need to manually type variable name
  • No source info, could easily get lost in a large program
  • Need to deal with fmt verbs
With debug.Debug
package main

import "github.com/FollowTheProcess/debug"

func main() {
    something := "hello"
    debug.Debug(something)
}
DEBUG: [/Users/you/projects/myproject/main.go:7:3] something = "hello"
  • Source info, yay! 🎉
  • Variable name is handled for you
  • Can handle any valid go expression or value
  • No fmt print verbs
Credits

This package was created with copier and the FollowTheProcess/go_copier project template.

Documentation

Overview

Package debug provides an easy mechanism to enable and streamline "print debugging" inspired by Rust's dbg macro.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(value any)

Debug prints the file, line number and the value to stderr in a nice human-readable format.

Any internal error is printed to stderr and the process halted.

something := "hello"
debug.Debug(something) // DEBUG: [/Users/you/projects/myproject/main.go:30:3] something = "hello"

Types

This section is empty.

Jump to

Keyboard shortcuts

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