ZapLog is a lightweight, flexible logging utility for Go applications, built on top of the fast and structured logging pkg zap.
go get github.com/yyle88/zaplog
You can log messages with key-value pairs using zaplog.LOG
:
zaplog.LOG.Debug("Debug message", zap.String("key", "value"))
zaplog.LOG.Error("Error message", zap.Error(errors.New("error")))
Log multiple fields in a single log entry by passing multiple key-value pairs:
zaplog.LOG.Debug("Debug message", zap.String("key1", "value1"), zap.Int("key2", 2))
zaplog.LOG.Error("Error message", zap.Int("key1", 1), zap.Error(errors.New("error")))
For simpler logging, you can use zaplog.SUG
, which supports variadic arguments for logging:
SUG.Debug("Simplified log", "key1", "value1", "key2", 2)
SUG.Error("Simplified error", errors.New("error"))
You can create sub-loggers with default fields for additional context, making your logs more informative. Use SubZap
, SubZap2
, or SubZap3
for creating sub-loggers:
zp := zaplog.LOGGER.SubZap(zap.String("module", "abc"), zap.String("key", "value"))
zp.LOG.Debug("Sub-log message", zap.Int("a", 1))
zp.SUG.Error("Simplified sub-log error", 1, 2, 3)
zp := zaplog.LOGGER.SubZap2("module", "abc", zap.String("key", "value"))
zp.LOG.Debug("Sub-log message 2", zap.Int("a", 2))
zp := zaplog.LOGGER.SubZap3("module", zap.String("key", "value"))
zp.LOG.Debug("Sub-log message 3", zap.Int("a", 3))
With SugaredLogger
, you can pass various argument types, including arrays and slices:
zaplog.SUG.Debug("Debug message", 1, 2, 3)
zaplog.SUG.Debug([]int{0, 1, 2})
We welcome contributions! Whether you’ve fixed a bug, improved documentation, or added a new feature, your contributions are greatly appreciated. Please follow the standard fork-and-pull request process.
ZapLog is open-source and released under the MIT License.
If you find this package valuable, give it a ⭐ on GitHub! Thank you for your support!!!