
[中文版本]
RainbowLog v1 is released! From v0.0.12 all the way to v1.0.1, this major release brings a cleaner package structure, a more concise API, and numerous performance optimizations and bug fixes. This article covers the key improvements from v0.0.12 to v1.0.1 and explains the API differences between the old and new versions.
Version Evolution
| Version | Highlights |
|---|---|
| v0.0.12 | Baseline |
| v0.0.13 | Windows console ANSI support |
| v0.0.14 | Major refactoring + Bug fixes + Performance optimizations + Test coverage |
| v1.0.0 | Package restructure: core moved to log/, global logger moved to global/ |
| v1.0.1 | Global logger package renamed from global/ to logger/ |
Detailed Changelog
v0.0.13 — Windows Console Color Support
Added record_packer_console_windows.go, enabling colored log output on Windows terminals. Windows users no longer have to suffer through monochrome logs.
v0.0.14 — Comprehensive Polish
The most change-intensive version before v1, with 22 commits:
Bug Fixes:
- Fixed short write error handling
- Added nil check for
[]byteinput inObjectDatamethod - Fixed duplicate first element issue when encoding duration slices
- Fixed SubLogger shallow copy —
writerEncodersnow uses deep copy, child Logger modifications no longer affect the parent - Attach detailed error info when loading config files fails
Performance Optimizations:
- Pre-built text encoder to avoid per-
createRecordallocation - Global logger changed to lazy init +
sync.Mutexdouble-check,init()removed - Caller path truncation logic optimized
New Features:
- Added
TimeFormatUnixNano(UNIXNANO) nanosecond time format - Added
TimestampFuncvariable for customizable time source (useful for testing)
Refactoring:
- Refactored
BufferedLevelWriterto properly implementLevelWriterinterface - Fixed text encoder incorrectly using
JSONMarshalFunc, replaced withTextMarshalFunc - Simplified
multiLevelWriter.WriteLevelimplementation NewTextEncoderchanged fromvartofunc- Removed unused mutex from
LogRecord
Testing: Added tests for encoder interface, hex, float/int slices, strings, etc.
Build: Go version upgraded from 1.23 to 1.26, added golang.org/x/sync dependency.
v1.0.0 — Package Restructure (Breaking Change)
The largest structural adjustment: all core files moved from the root into the log/ sub-package, and the global logger moved from log/global_logger.go to the new global/ package.
| Old Path (v0.x) | New Path (v1.0.0) |
|---|---|
encoder.go |
log/encoder.go |
logger.go |
log/logger.go |
option.go |
log/option.go |
record.go |
log/record.go |
writer.go |
log/writer.go |
log/global_logger.go |
global/global_logger.go |
v1.0.1 — Global Logger Package Renamed (Breaking Change)
Global logger package renamed from global/ to logger/ for better clarity.
Old vs. New API Comparison
1. Global Logger — Import Path & Calling Convention
v0.x (old way):
1 | import "github.com/rambollwong/rainbowlog/log" |
v1.x (new way):
1 | import "github.com/rambollwong/rainbowlog/logger" |
⚠️ Changes:
- Import path:
rainbowlog/log→rainbowlog/logger- Calling convention:
log.Logger.Info()→logger.Info()(package-level convenience function)- Initialization: from
init()auto-call to lazy init on first use
2. Custom Logger — Type Prefix Changes
v0.x (old way):
1 | import "github.com/rambollwong/rainbowlog" |
v1.x (new way):
1 | import "github.com/rambollwong/rainbowlog/log" |
⚠️ All type and function prefixes change from
rainbowlog.XXXtolog.XXX.
3. Complete Type Reference Mapping
| Concept | v0.x Prefix | v1.x Prefix |
|---|---|---|
| Logger type | *rainbowlog.Logger |
*log.Logger |
| Constructor | rainbowlog.New(...) |
log.New(...) |
| Option type | rainbowlog.Option |
log.Option |
| Record type | rainbowlog.Record |
log.Record |
| Hook types | rainbowlog.Hook / rainbowlog.HookFunc |
log.Hook / log.HookFunc |
| LevelWriter | rainbowlog.LevelWriter |
log.LevelWriter |
| Encoders | rainbowlog.JsonEnc / rainbowlog.TextEnc |
log.JsonEnc / log.TextEnc |
| Time format constants | rainbowlog.TimeFormatUnix |
log.TimeFormatUnix |
| ConsolePacker | rainbowlog.ConsolePacker |
log.ConsolePacker |
| Global functions | rainbowlog.GlobalCallerMarshalFunc |
log.GlobalCallerMarshalFunc |
4. Default Config File Name Change
| Version | Default Config File |
|---|---|
| v0.x | rainbowlog.yaml |
| v1.x | log.yaml |
5. New Features at a Glance
Nanosecond time format (added in v0.0.14):
1 | log.WithTimeFormat(log.TimeFormatUnixNano) // outputs nanosecond Unix timestamp |
Customizable time source (added in v0.0.14):
1 | log.TimestampFunc = func() time.Time { |
SubLogger deep copy (fixed in v0.0.14): child Logger’s writerEncoders is now an independent copy — modifying a child Logger no longer affects the parent.
Upgrade Guide
To upgrade from v0.x to v1.x:
- Global Logger import:
"rainbowlog/log"→"rainbowlog/logger" - Global Logger calls:
log.Logger.XXX()→logger.XXX()(package-level functions) - Custom Logger import: switch to
"rainbowlog/log", type prefixrainbowlog.→log. - Config file: default filename
rainbowlog.yaml→log.yaml - Go version: requires Go 1.26+
Github Repository
https://github.com/rambollwong/rainbowlog
If you find this project useful, please give it a ⭐. Your support is my greatest motivation!
💰 Support with a Donation
If you like this project, feel free to buy the author a cup of lemonade ☕️. Your support is my motivation for continuous updates!
- WeChat Pay:
- Alipay: