zapplus

package module
v0.0.0-...-fee5387 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 4 Imported by: 0

README ยถ

zap-plus

A lightweight and extensible logging library built on top of Uber's Zap, providing a simplified interface for structured logging in Go applications.

Features

  • ๐Ÿš€ High Performance: Built on Uber Zap's high-performance logging foundation
  • ๐ŸŽฏ Simple Interface: Clean and intuitive API for common logging operations
  • ๐Ÿ”ง Configurable: Support for different log levels and configurations
  • ๐Ÿ“ฆ Lightweight: Minimal overhead with focused functionality
  • ๐Ÿ—๏ธ Extensible: Modular design for easy customization and extension

Installation

go get github.com/hanzhang418/zap-plus

Quick Start

package main

import (
    "github.com/hanzhang418/zap-plus"
    "go.uber.org/zap"
    "go.uber.org/zap/zapcore"
)

func main() {
    // Create a new logger with Info level
    logger, err := zap_plus.New(zapcore.InfoLevel)
    if err != nil {
        panic(err)
    }

    // Log some messages
    logger.Info("Application started", zap.String("version", "1.0.0"))
    logger.Warn("This is a warning", zap.Int("code", 404))
    logger.Error("An error occurred", zap.Error(err))
}

API Reference

Creating a Logger
func New(level zapcore.Level) (logger.Logger, error)

Creates a new logger instance with the specified log level.

Parameters:

  • level: The minimum log level (e.g., zapcore.DebugLevel, zapcore.InfoLevel, zapcore.WarnLevel, zapcore.ErrorLevel)

Returns:

  • logger.Logger: Logger interface instance
  • error: Error if logger creation fails
Logger Interface

The logger.Logger interface provides the following methods:

type Logger interface {
    Info(msg string, fields ...zap.Field)
    Warn(msg string, fields ...zap.Field)
    Error(msg string, fields ...zap.Field)
}
Methods
  • Info(msg string, fields ...zap.Field): Log an info-level message
  • Warn(msg string, fields ...zap.Field): Log a warning-level message
  • Error(msg string, fields ...zap.Field): Log an error-level message

All methods accept a message string and optional structured fields using Zap's field types.

Examples

Basic Logging
logger, _ := zap_plus.New(zapcore.InfoLevel)

logger.Info("User logged in",
    zap.String("username", "john_doe"),
    zap.String("ip", "192.168.1.1"))

logger.Warn("High memory usage",
    zap.Float64("usage_percent", 85.5))

logger.Error("Database connection failed",
    zap.String("database", "users"),
    zap.Duration("timeout", time.Second*30))
Different Log Levels
// Debug level logger (logs everything)
debugLogger, _ := zap_plus.New(zapcore.DebugLevel)

// Error level logger (only logs errors)
errorLogger, _ := zap_plus.New(zapcore.ErrorLevel)

// Info level logger (logs info, warn, and error)
infoLogger, _ := zap_plus.New(zapcore.InfoLevel)
Structured Logging with Fields
logger, _ := zap_plus.New(zapcore.InfoLevel)

// Using various field types
logger.Info("Request processed",
    zap.String("method", "GET"),
    zap.String("path", "/api/users"),
    zap.Int("status_code", 200),
    zap.Duration("response_time", time.Millisecond*150),
    zap.Bool("cached", true))

Project Structure

zap-plus/
โ”œโ”€โ”€ zapplus.go              # Main package entry point
โ”œโ”€โ”€ pkg/
โ”‚   โ””โ”€โ”€ logger/
โ”‚       โ””โ”€โ”€ logger.go       # Logger interface definition
โ”œโ”€โ”€ internal/
โ”‚   โ””โ”€โ”€ builder/
โ”‚       โ””โ”€โ”€ builder.go      # Logger builder implementation
โ”œโ”€โ”€ go.mod                  # Go module definition
โ”œโ”€โ”€ LICENSE                 # MIT License
โ””โ”€โ”€ README.md              # This file

Dependencies

Requirements

  • Go 1.23.4 or later

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built on top of Uber's Zap logging library
  • Inspired by the need for a simpler logging interface while maintaining high performance

Documentation ยถ

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

This section is empty.

Functions ยถ

func New ยถ

func New(level zapcore.Level) (logger.Logger, error)

New ๆ˜ฏๅบ“็š„ๅ”ฏไธ€ๅ…ฅๅฃ๏ผŒ็”จไบŽๅˆ›ๅปบไธ€ไธชๆ–ฐ็š„ Logger ๅฎžไพ‹ใ€‚

Types ยถ

This section is empty.

Directories ยถ

Path Synopsis
internal
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL