DD
DD (read as "data-driven" or "distributed debugger" in the source comments) is a high-performance structured logging library from the CyberGo organization, providing thread-safe log recording, flexible output target configuration, and comprehensive security protection.
Features
- Structured Logging -- Type-safe field recording with optional JSON output
- Multiple Output Targets -- Simultaneous output to console, file, and custom
io.Writer - File Rotation -- Automatic size-based rotation with configurable backup count and retention policies
- Sensitive Data Filtering -- Built-in regex patterns for automatic redaction of passwords, keys, tokens, and other sensitive information
- Field Validation -- Field key naming convention validation (snake_case/camelCase, etc.) with Log4Shell injection protection
- Audit Logging -- Asynchronous audit event recording with HMAC integrity signing and sequence numbers
- Hook System -- Lifecycle hooks including BeforeLog, AfterLog, OnRotate, and more
- Context Integration -- Provides TraceID/SpanID/RequestID context utilities and a ContextExtractor extension point (logging methods do not accept
ctx; pass fields viaWithFields) - Log Sampling -- Optional log sampling strategy for high-throughput scenarios
- Low-Allocation Optimization -- Minimized memory allocation on hot paths for exceptional performance
Installation
bash
go get github.com/cybergodev/ddQuick Start
go
package main
import (
"time"
"github.com/cybergodev/dd"
)
func main() {
// Use the default logger
dd.Info("service started")
// Structured logging
dd.InfoWith("request completed",
dd.String("method", "GET"),
dd.Int("status", 200),
dd.Duration("elapsed", 150*time.Millisecond),
)
// Create a custom logger
logger, _ := dd.New(dd.DefaultConfig())
defer logger.Close()
logger.Info("custom logger created")
}Module Navigation
| Module | Description |
|---|---|
| Core Concepts | Logger hierarchy, processing pipeline, interface levels |
| Configuration | Config struct, presets, output targets |
| Structured Logging | Field constructors, method chaining |
| File Output & Rotation | FileWriter, BufferedWriter |
| Sensitive Data Filtering | Auto-redaction, security levels |
| Field Validation | Naming convention checks, Log4Shell protection |
| Log Sampling | High-throughput log volume reduction |
| Audit Logging | Asynchronous audit events, integrity signing |
| Hook System | Lifecycle hook extensions |
| Error Handling | Structured errors, sentinel errors, errors.Is |
| Distributed Tracing | TraceID/SpanID/RequestID |
| Migration Guide | Migrate from log/slog/zap/logrus |
Next Steps
- Installation -- Requirements and integration
- Quick Start -- 5-minute getting started guide
- Core Concepts -- Understand DD architecture
- Configuration -- Full Config fields and presets
- Cheat Sheet -- Common API quick reference
- API Reference -- Complete API documentation
- Basic Examples -- Practical code examples
- Migration Guide -- Migrate from log/slog/zap/logrus