pnmd

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

pnmd

🪵 My personal slog.Handler with struct fields

pnmd provides a minimal slog.Handler based on pterm that prints logs as a compact tree: timestamp, level, message, structured attributes, and optional caller info.

Demo

demo


Example

package main

import (
	"log/slog"
	"os"

	"github.com/TallSmaN/pnmd"
)

func main() {
	logger := slog.New(
		pnmd.NewHandler(os.Stdout, &pnmd.Options{
			Level: slog.LevelDebug,
			CallerEnabled: map[slog.Level]bool{
				slog.LevelDebug: true,
				slog.LevelInfo:  true,
				slog.LevelWarn:  true,
				slog.LevelError: true,
			},
			TimeFormat: "2006/01/02 15:04:05",
			Padding:    3,
		}),
	)

	logger.Debug("initializing cache subsystem", "cache", "redis", "host", "localhost", "port", 6379)

	logger.Info("cache connected")

	logger.Warn("slow query detected", "duration_ms", 1823, "query", "SELECT * FROM users WHERE active=1", "user", "analytics-worker")

	logger.Error("failed to write audit event", "error", "disk full", "path", "/var/log/audit.json", "component", "audit", "retry_in_sec", 30)

	logger.Debug("config reloaded", "file", "/etc/app/config.yaml", "changes", 5)

	logger.Info("http server started", "addr", ":8080", "threads", 8)

	logger.Warn("deprecated API usage", "endpoint", "/v1/legacy", "client", "mobile-android", "version", "1.2.0")

	logger.Error("user authentication failed", "user", "john", "ip", "192.168.1.42", "reason", "invalid token")

	logger.Debug("background job finished", "job_id", "import-2025-11-05", "rows", 152_000, "duration_sec", 94.2)

	logger.Info("graceful shutdown complete", "uptime_min", 238)
}


This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler added in v1.0.2

func NewHandler(w io.Writer, opts *Options) *h.Handler

NewHandler creates a new log handler using the provided options or defaults if nil.

Types

type Options

type Options = opts.Options

func DefaultOptions added in v1.0.2

func DefaultOptions() *Options

DefaultOptions returns a new Options instance initialized with default values.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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