Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents a debug logger for a specific namespace
func New ¶
New creates a new Logger for the given namespace. The enabled state is computed at construction time based on the DEBUG environment variable. DEBUG syntax follows https://www.npmjs.com/package/debug patterns:
DEBUG=* - enables all loggers DEBUG=namespace:* - enables all loggers in a namespace DEBUG=ns1,ns2 - enables specific namespaces DEBUG=ns:*,-ns:skip - enables namespace but excludes specific patterns
Colors are automatically assigned to each namespace if DEBUG_COLORS != "0" and stderr is a TTY.
Example ¶
package main
import (
"fmt"
"os"
"github.com/githubnext/gh-aw/pkg/logger"
)
func main() {
// Set DEBUG environment variable to enable loggers
os.Setenv("DEBUG", "app:*")
defer os.Unsetenv("DEBUG")
// Create a logger for a specific namespace
log := logger.New("app:feature")
// Check if logger is enabled
if log.Enabled() {
fmt.Println("Logger is enabled")
}
}
Output: Logger is enabled
Example (Patterns) ¶
package main
import (
"os"
)
func main() {
// Example patterns for DEBUG environment variable
// Enable all loggers
os.Setenv("DEBUG", "*")
// Enable all loggers in workflow namespace
os.Setenv("DEBUG", "workflow:*")
// Enable multiple namespaces
os.Setenv("DEBUG", "workflow:*,cli:*")
// Enable all except specific patterns
os.Setenv("DEBUG", "*,-workflow:test")
// Enable namespace but exclude specific loggers
os.Setenv("DEBUG", "workflow:*,-workflow:cache")
defer os.Unsetenv("DEBUG")
}
func (*Logger) Print ¶
func (l *Logger) Print(args ...interface{})
Print prints a message if the logger is enabled. A newline is always added at the end. Time diff since last log is displayed like the debug npm package.
Example ¶
package main
import (
"os"
"github.com/githubnext/gh-aw/pkg/logger"
)
func main() {
// Enable all loggers
os.Setenv("DEBUG", "*")
defer os.Unsetenv("DEBUG")
log := logger.New("app:feature")
// Print concatenates arguments like fmt.Sprint
log.Print("Processing", " ", "items")
// Output to stderr: app:feature Processing items +0ns
}
func (*Logger) Printf ¶
Printf prints a formatted message if the logger is enabled. A newline is always added at the end. Time diff since last log is displayed like the debug npm package.
Example ¶
package main
import (
"os"
"github.com/githubnext/gh-aw/pkg/logger"
)
func main() {
// Enable all loggers
os.Setenv("DEBUG", "*")
defer os.Unsetenv("DEBUG")
log := logger.New("app:feature")
// Printf uses standard fmt.Printf formatting
log.Printf("Processing %d items", 42)
// Output to stderr: app:feature Processing 42 items
}