logkit

package
v0.0.0-...-5d01d84 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: MIT Imports: 7 Imported by: 0

README

Logkit Module

Zap logger integration for Fx applications.

Features

  • Provides both *zap.Logger and *zap.SugaredLogger.
  • Configurable encoding (production, json, development).
  • Configurable log level.
  • Logs service metadata (via runtimeinfo) on startup.
  • Flushes buffered logs on shutdown.

Config

logger:
  encoding: production  # or development/json
  level: info           # debug|info|warn|error

Validation enforces that encoding is one of production|prod|json|development|dev|console and that level resolves to a valid Zap level. Startup fails if the values are out of range.

Usage

app := fx.New(
  logkit.Module(),
  fx.Invoke(func(log *zap.Logger) {
    log.Info("hello")
  }),
)

Documentation

Overview

Package logkit provides a configurable *zap.Logger for uber/fx applications.

The module allows configuration for different environments (e.g., "production" for structured JSON logs, "development" for human-readable console logs) and log levels. It also automatically logs service metadata on startup and ensures log buffers are flushed on shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Module

func Module() fx.Option

Module provides a configured *zap.Logger and *zap.SugaredLogger to the Fx application container.

func New

func New(cfg Config) (*zap.Logger, error)

New constructs a new *zap.Logger based on the provided configuration. It enriches the logger with application metadata from the runtimeinfo package.

func RegisterHooks

func RegisterHooks(lc fx.Lifecycle, log *zap.Logger)

registerHooks attaches OnStart and OnStop hooks to the application lifecycle.

Types

type Config

type Config struct {
	// Encoding sets the logger's output format. Use "production|json" for JSON
	// or "development" for a human-readable console format.
	Encoding string `yaml:"encoding" validate:"required,oneof=production prod json development dev console"`

	// Level is the minimum log level to record, e.g., "debug", "info", "warn".
	Level string `yaml:"level" validate:"required,oneof=debug info warn error dpanic panic fatal"`
}

Config defines the configuration for the logger.

Jump to

Keyboard shortcuts

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