How nkmr-jp/zl works
Project type and purpose
• This is an open-source Go logging library (“zl”) built as a wrapper around Uber’s zap.
• Its goal is to provide developer-friendly log formatting (console, JSON, rotated files) and rich features (error aggregation, stack traces, custom fields).
File structure
• Top-level files:
• zl.go, logger.go, rotate.go, pretty.go, options.go, field.go – core package source files
• *_test.go – unit tests for each module
• Makefile, .github/workflows, go.mod, go.sum, CI configs – build, test, and release orchestration
• examples/ directory: demonstrates integration in various contexts (basic app, HTTP server, Google Cloud Functions)
• testdata/: sample JSONL logs used by tests
README for additional insights
• Describes four main output strategies: PrettyOutput, ConsoleOutput, FileOutput, ConsoleAndFileOutput
• Shows initialization steps (SetLevel, SetOmitKeys, Init, Sync) and usage patterns (Info, Warn, Err)
• Mentions underlying dependency on zap and log‐file rotation support
Main components of the system
a. Public API layer (zl package)
– Init(), Sync(), SetLevel(), SetOmitKeys(), Info(), Warn(), Debug(), Err()
b. Configuration & options
– Options struct, default values, keys to omit
c. Output strategy implementations
– PrettyOutput
– ConsoleOutput
– FileOutput (incorporating rotate.go)
– ConsoleAndFileOutput
d. Underlying zap core
– zap.Logger, zapcore.Core, zap.Fields
e. External outputs/services
– Stdout/stderr (console)
– Log file with rotation
– Third-party log collectors (e.g. Google Cloud Logging)
Relationships and interactions
• The consumer calls Public API → zl package
• zl package reads configuration & selects one OutputStrategy
• Strategy creates/configures a zap.Logger instance
• Calls to Info/Err/etc. flow into zapcore, then out to destinations: console and/or file
• rotate.go handles file rotation under the FileOutput strategy
• Examples (in examples/) act as external clients showing integration
Architectural patterns and design principles
• Strategy pattern for pluggable output strategies
• Configuration-driven initialization
• Wrapper/facade over zap to simplify and standardize logging calls
• Separation of concerns: formatting (pretty vs JSON) separated from output (console vs file)
Technologies, frameworks, and libraries
• Go (golang) modules
• zap (Uber’s high-performance logger)
• lumberjack or custom rotate.go for file rotation
• GitHub Actions for CI/CD
• jq recommended for JSON log filtering