debuggefire

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT

README

debuggefire 🔥

Automatic Go function instrumentation tool that adds timing measurements and debug logging to your code.

Installation

go install github.com/alexshd/debuggefire/cmd/debuggefire@latest

Or build from source:

git clone https://github.com/alexshd/debuggefire.git
cd debuggefire
go build -o debuggefire ./cmd/debuggefire

Quick Start

# Add timing to a file
debuggefire add myfile.go

# Add to entire package recursively
debuggefire add ./pkg --recursive

# Remove instrumentation when done
debuggefire remove ./pkg --recursive

After instrumenting, install the required dependency:

go get github.com/lmittmann/tint

What It Does

Transforms this:

package main

func Calculate(x, y int) int {
    return x + y
}

Into this:

package main

import (
    "log/slog"
    "os"
    "time"
    "github.com/lmittmann/tint"
)

func init() {
    slog.SetDefault(slog.New(
        tint.NewHandler(os.Stderr, &tint.Options{
            Level:      slog.LevelDebug,
            TimeFormat: "15:04:05.0000",
            NoColor:    false,
            AddSource:  true,
        }),
    ))
}

func Calculate(x, y int) int {
    __debuggefire_t0__ := time.Now()
    defer func() {
        slog.Debug("Calculate completed",
            "duration", time.Since(__debuggefire_t0__))
    }()
    return x + y
}

Commands

add

Add timing instrumentation to Go files.

debuggefire add [file or directory] [flags]

Flags:
  -r, --recursive   Process directories recursively
  -b, --backup      Create backup files (.bak) (default: true)
remove

Remove timing instrumentation from Go files.

debuggefire remove [file or directory] [flags]

Flags:
  -r, --recursive   Process directories recursively
  -b, --backup      Create backup files (.bak) (default: true)

Example

# Add instrumentation
debuggefire add ./mypackage --recursive

# Install required dependency
go get github.com/lmittmann/tint

# Run your code - see colored debug output!
go run main.go

Output example:

09:54:53 DBG myfile.go:19 Calculate completed duration=123.456µs
09:54:53 DBG myfile.go:27 ProcessData completed duration=2.345ms

When done debugging:

# Remove all instrumentation
debuggefire remove ./mypackage --recursive

How It Works

  • Uses Go's AST parser for safe code manipulation
  • Injects timing variable and defer statement at function start
  • Automatically manages imports (time, log/slog, os, tint)
  • Skips init() functions to avoid recursion
  • Creates backups by default (disable with --backup=false)

Requirements

  • Go 1.21+ (uses log/slog)
  • Your project needs github.com/lmittmann/tint after instrumentation

Testing

go test ./...

License

MIT

Directories

Path Synopsis
cmd
debuggefire command
internal
cmd
instrumenter
Package instrumenter provides functionality to inject and remove timing instrumentation and debug logging in Go source files.
Package instrumenter provides functionality to inject and remove timing instrumentation and debug logging in Go source files.

Jump to

Keyboard shortcuts

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