fmtlog

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package fmtlog adds Sprintf-style log messages as a LogLayer plugin. Register it once and every call site that passes a format string followed by arguments gets fmt.Sprintf semantics:

log.AddPlugin(fmtlog.New())

log.Info("user %d signed in", userID)
log.WithMetadata(loglayer.Metadata{"reqId": id}).
    Error("request %s failed: %v", id, err)

Without the plugin, multi-argument calls are space-joined (`fmt.Sprintf("%v", arg)` per element). Registering New opts the logger into format-string semantics: any call where the first message is a string and there are extra arguments is rewritten to fmt.Sprintf(messages[0], messages[1:]...) before downstream MessageHooks run.

See https://go.loglayer.dev for usage guides and the full API reference.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() loglayer.Plugin

New returns a plugin that resolves multi-argument log messages via fmt.Sprintf. The plugin is a single MessageHook: zero hot-path cost when a call has only one message; one Sprintf when there are extras.

Example

New returns a plugin that rewrites multi-argument log messages via fmt.Sprintf when the first message is a format string. Single-message calls are untouched.

tr := lltesting.New(lltesting.Config{})
log := loglayer.New(loglayer.Config{
	Transport:        tr,
	DisableFatalExit: true,
	Plugins:          []loglayer.Plugin{fmtlog.New()},
})

log.Info("user %d signed in", 42)

line := tr.Library.PopLine()
fmt.Println(line.Messages[0])
Output:
user 42 signed in

Types

This section is empty.

Jump to

Keyboard shortcuts

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