ZL-Asica/zlog

★ 1Forks 0GoGitHub ↗Compare

README

zlog

A cute and configurable logging library for Go, based on Go 1.21+ log/slog.

Supports emoji decoration, structured output, JSON mode, and custom output writers.

✨ Features

  • ✅ Simple API: Info, Warn, Error
  • 🧱 Structured logging with key-value pairs
  • 🎨 Emoji decorations (optional)
  • 🧾 JSON output mode for machine consumption (optional)
  • 🌈 Color output in terminal (via slog.TextHandler)
  • 🔌 Pluggable output (stdout, file, multiwriter, etc)

📦 Installation

go get github.com/ZL-Asica/zlog

🚀 Quick Start

package main

import (
    "github.com/ZL-Asica/zlog"
    "log/slog"
)

func main() {
    zlog.Init(&zlog.Options{
        Level: slog.LevelDebug,
        Emoji: true,
        JSON:  false,
    })

    zlog.Info("System startup complete", "user", "asica")
    zlog.Warn("Unusual response time", "duration", "450ms")
    zlog.Error("Something went wrong", "code", 500, "reason", "timeout")
}

🛠 Config Options

Option Type Description
Level slog.Level Log level (Debug, Info, Warn, Error)
Emoji bool Enable emoji decorations
JSON bool Use JSON structured logging
Writer io.Writer Output destination (default: os.Stdout)

🧪 Example Output

ℹ️  System startup complete user=elara
⚠️  Unusual response time duration=450ms
❌ Something went wrong code=500 reason=timeout

Or in JSON mode:

{
  "time": "2025-05-29T12:00:00Z",
  "level": "INFO",
  "msg": "System startup complete",
  "user": "asica"
}

📄 License

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

Contributors

ZL-Asica

Issues