pnmd

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 2 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.

Example output

demo


Example

package main

import (
	"log/slog"

	"github.com/TallSmaN/pnmd"
)

func main() {
	pnmd.Configure(pnmd.Options{
		Level: slog.LevelDebug,
		CallerEnabled: map[slog.Level]bool{
			slog.LevelDebug: true,
			slog.LevelInfo:  true,
			slog.LevelWarn:  true,
			slog.LevelError: true,
		},
	})

	log := pnmd.Get()

	log.Info("server started", "addr", ":8080")
	log.Debug("cache primed", "keys", "123")

	pnmd.SetLevel(slog.LevelWarn)
	log.Warn("slow request", "latency", "230ms")
	log.Error("write failed", "path", "/tmp/out.log")
}

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(o Options)

Configure replaces the global configuration and logger. Not concurrency-safe; prefer calling during process initialization.

func DisableCallerFor

func DisableCallerFor(levels ...slog.Level)

DisableCallerFor disables caller display for the given levels. If the caller map is nil, defaults are restored first. Not concurrency-safe.

func EnableCallerFor

func EnableCallerFor(levels ...slog.Level)

EnableCallerFor enables caller display for the given levels. If the caller map is nil, defaults are restored first. Not concurrency-safe.

func Get

func Get() *slog.Logger

Get returns the package-level logger, constructing it on first use. Not concurrency-safe; call from init or a single goroutine during setup.

func SetLevel

func SetLevel(level slog.Level)

SetLevel updates the minimum enabled level on the global logger. Not concurrency-safe; racing calls may produce undefined results.

Types

type Options

type Options = log.Config

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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