debugo

package module
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 11 Imported by: 4

README

debugo

Coverage Status

A lightweight, colorful, and flexible logging utility for Go — inspired by debug in Node.js.

debugo provides namespaced, timestamped, and color-coded logging with support for inclusion/exclusion patterns and pluggable output streams.


✨ Features

  • ✅ Namespaced debug logs (namespace:subspace)
  • 🎨 Automatic and consistent color assignment per namespace
  • 🕒 Time elapsed since last log (e.g., +3ms)
  • 🧪 Wildcard-based inclusion/exclusion filtering (*, ?, -namespace:*)
  • 🔐 Thread-safe logging with sync.RWMutex
  • 🧰 Custom timestamp format and output writer support
  • 🎨 JSON output support
  • 🎨 Fields output support

📦 Installation

go get github.com/yosev/debugo

🚀 Quick Start

package main

import (
	"github.com/yosev/debugo"
)

func main() {
	debugo.SetNamespace("*") // Enable all logs

	log := debugo.New("app")
	log.Debug("Hello, debugo!")

	sublog := log.Extend("submodule")
	sublog.Debug("Detailed submodule log")
}
Output
15:04:05.123 app Hello, debugo! +0ms
15:04:05.123 app:submodule Detailed submodule log +1ms

🧩 API Reference

Logger Creation
Function Description
New(name string) Creates a new debugger for the namespace
Extend(name string) Creates a sub-namespace logger
Logging Methods
Method Description
Debug(args ...any) Print values to the output stream
Debugf(format, ...) Formatted output like fmt.Printf

⚙️ Configuration

Enable/Disable Namespaces
debugo.SetNamespace("*")                      // Enable all namespaces
debugo.SetNamespace("api:*")                  // Enable 'api' with sub spaces
debugo.SetNamespace("api:*, -api:auth")       // Enable `api:*` with sub spaces except `api:auth`
debugo.SetNamespace("api:?") 						      // Enable `api` with optional with sub spaces
debugo.SetNamespace("")                       // Disable all logging

Supports wildcards (*), optional sub spcaces (?), and negation (-).

Output Stream
f, _ := os.Create("debug.log")
debugo.SetOutput(f) // Send logs to a file instead of stdout

You can also set it back to os.Stdout or os.Stderr as needed.

Timestamp Format
debugo.SetTimestamp(&debugo.Timestamp{
	Format: "15:04:05", // HH:MM:SS (default)
})

Use any Go-compliant time format layout.


✅ Testing

go test -v -race ./...

If using make:

make test

📁 Project Structure

debugo/
├── debugo.go      // main library
├── color.go       // color functions
├── runtime.go     // global runtime configuration
├── namespace.go   // namespace functions
├── time.go        // timestamp functions
└── write.go       // output writer

🤝 Contributing

Contributions are very welcome!

  • Fork this repo
  • Create a new branch: git checkout -b feature-name
  • Make changes and commit: git commit -am 'Add feature'
  • Push: git push origin feature-name
  • Create a pull request

📄 License

MIT License © 2025 YoSev

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNamespace added in v0.4.1

func GetNamespace() string

GetNamespace retrieves the current global namespace for debugging.

func GetOutput added in v0.2.6

func GetOutput() io.Writer

GetOutput retrieves the current global output configuration for debugging.

func GetUseColors added in v0.6.0

func GetUseColors() bool

GetUseColors retrieves the current global color usage for debugging.

func SetFormat added in v0.6.2

func SetFormat(format Format)

SetFormat sets the global output format for debugging.

func SetNamespace added in v0.4.1

func SetNamespace(namespace string)

SetNamespace sets the global namespace for debugging.

func SetOutput added in v0.2.6

func SetOutput(output io.Writer)

SetOutput sets the global output configuration for debugging.

func SetTimestamp added in v0.2.3

func SetTimestamp(timestamp *Timestamp)

SetTimestamp sets the global timestamp configuration for debugging.

func SetUseColors added in v0.6.0

func SetUseColors(use bool)

SetUseColors sets the global color usage for debugging.

Types

type Debugger added in v0.2.0

type Debugger struct {
	// contains filtered or unexported fields
}

func New

func New(namespace string) *Debugger

New creates a new debugger instance

func (*Debugger) Debug added in v0.2.0

func (d *Debugger) Debug(message ...any) *Debugger

Debug logs a message if the debuggers namespace matches

func (*Debugger) Debugf added in v0.2.0

func (d *Debugger) Debugf(format string, message ...any) *Debugger

Debugf logs a formatted message if the debuggers namespace matches

func (*Debugger) Extend added in v0.2.0

func (d *Debugger) Extend(namespace string) *Debugger

Extend creates a new debugger instance with an extended namespace

func (*Debugger) SetOutput added in v0.4.1

func (d *Debugger) SetOutput(output io.Writer)

SetOutput sets the output writer for the debugger instance

func (*Debugger) With added in v0.6.2

func (d *Debugger) With(key string, value any) *Debugger

With clones the debugger instance and adds a key-value pair to its fields (json serializeable)

type Format added in v0.6.2

type Format string
const (
	Plain Format = "plain"
	JSON  Format = "json"
)

func GetFormat added in v0.6.2

func GetFormat() Format

GetFormat retrieves the current global output format for debugging.

type Timestamp

type Timestamp struct {
	Format string
}

func GetTimestamp added in v0.4.1

func GetTimestamp() *Timestamp

GetTimestamp retrieves the current global timestamp configuration for debugging.

Jump to

Keyboard shortcuts

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