Skip to content
/ zaplog Public

**zaplog** is a lightweight, flexible logging pkg for Go applications, built on top of the fast and structured logging pkg zap.

License

Notifications You must be signed in to change notification settings

yyle88/zaplog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

cc4a9a3 · Feb 20, 2025

History

25 Commits
Dec 25, 2024
Feb 10, 2025
Feb 20, 2025
Feb 10, 2025
Feb 10, 2025
Nov 26, 2024
Nov 26, 2024
Nov 26, 2024
Nov 26, 2024
Feb 10, 2025
Feb 10, 2025
Feb 10, 2025
Feb 10, 2025
Nov 26, 2024
Nov 26, 2024
Feb 10, 2025
Feb 10, 2025
Feb 10, 2025
Feb 10, 2025
Feb 10, 2025
Feb 10, 2025
Feb 10, 2025
Feb 10, 2025

Repository files navigation

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

ZapLog - Flexible and High-Performance Logging for Go

ZapLog is a lightweight, flexible logging utility for Go applications, built on top of the fast and structured logging pkg zap.

README

中文说明

Installation

go get github.com/yyle88/zaplog

Core Features

1. Basic Logging

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")))

2. Logging Multiple Key-Value Pairs

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")))

3. Using SugaredLogger

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"))

4. Creating Sub-Loggers (SubZap)

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:

SubLogger Creation with SubZap:

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)

SubLogger Creation with SubZap2:

zp := zaplog.LOGGER.SubZap2("module", "abc", zap.String("key", "value"))
zp.LOG.Debug("Sub-log message 2", zap.Int("a", 2))

SubLogger Creation with SubZap3:

zp := zaplog.LOGGER.SubZap3("module", zap.String("key", "value"))
zp.LOG.Debug("Sub-log message 3", zap.Int("a", 3))

5. Handling Multiple Arguments in Sugared Logger

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})

Contributing

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.

License

ZapLog is open-source and released under the MIT License.

Thank You

If you find this package valuable, give it a ⭐ on GitHub! Thank you for your support!!!

About

**zaplog** is a lightweight, flexible logging pkg for Go applications, built on top of the fast and structured logging pkg zap.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published