log

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 5 Imported by: 0

README

Logger Package

The engine/log package provides a standardized logging interface built on top of uber-go/zap. It automatically switches between human-readable console output and structured JSON based on the environment.

Features

  • Environment Awareness:
    • Dev Mode: Pretty-printed console output with colors and simplified format.
    • Production Mode: Structured JSON output optimized for log aggregators (Elasticsearch, Loki, etc.).
  • Consistent Metadata: Automatically includes host, service, version (via context), and pid.
  • Custom Encoders: Tailored timestamp and caller formatters for better readability in dev mode.

Installation

go get github.com/mbu-id/engine/log

Quick Start

Initialization

Use NewLogger to create a standard logger instance. This is typically handled by engine.Init but can be used standalone.

package main

import (
    "github.com/mbu-id/engine/log"
    "go.uber.org/zap"
)

func main() {
    // Create a logger named "my-service"
    // true = Development Mode (Console)
    // false = Production Mode (JSON)
    logger := log.NewLogger("my-service", true)

    logger.Info("Service started",
        zap.String("port", ":8080"),
        zap.Int("workers", 5),
    )

    // Output (Dev):
    // 13/01 10:00:00 INFO @main.go:15 Service started {"port": ":8080", "workers": 5}
}

Configuration

The logger configuration is internal but adapts based on the isDev flag passed to NewLogger.

Feature Dev Mode (true) Production Mode (false)
Encoding Console (Text) JSON
Level DEBUG INFO
Output Stderr Stderr
Colors Yes No
Time Format DD/MM HH:mm:ss ISO8601

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorRed   = ansiWrapper(textRed)
	ColorGreen = ansiWrapper(textGreen)
	ColorWhite = ansiWrapper(textWhite)
	ColorGray  = ansiWrapper(textGray)

	BgBlack = ansiWrapper(bgBlack)
	BgRed   = ansiWrapper(bgRed)
	BgGreen = ansiWrapper(bgGreen)

	Reset     = ansiWrapper(styleReset)
	Bold      = ansiWrapper(styleBold)
	Dim       = ansiWrapper(styleDim)
	Italic    = ansiWrapper(styleItalic)
	Strikeout = ansiWrapper(styleStrikeout)
)

Public style helpers

Functions

func ErrorColor

func ErrorColor(v any) string

func NewLogger

func NewLogger(name string, isDev bool) *zap.Logger

NewLogger creates a named logger using the global config.

func SuccessColor

func SuccessColor(v any) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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