logx

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logx builds an slog logger configured the same way in every project.

Index

Constants

View Source
const AlertKey = "alert"

AlertKey is the attribute that raises an alert from an ordinary log line:

log.ErrorContext(ctx, "the pool is empty", logx.AlertKey, "pool_empty")

Its value is the alert kind. The platform counts such lines in app_alerts_total{kind}, so a use case needs no metric of its own to page someone.

Variables

This section is empty.

Functions

func Alerts added in v0.5.7

func Alerts(next slog.Handler, count func(kind string)) slog.Handler

Alerts wraps a handler: count receives the kind of every record that carries AlertKey, either in the record itself or in attributes added with With. Attributes inside a group are not top level and do not count. The record is passed on unchanged.

An alert is counted whatever the log level: a service running with LOG_LEVEL=error still counts a warning that raised one, though the line itself is not written. Debug lines are the exception, so that disabled debug logging stays free.

func Level

func Level(s string) slog.Level

Level parses a log level. Anything unknown becomes info.

func New

func New(o Options) *slog.Logger

New creates a logger.

Types

type Options

type Options struct {
	Level  string // debug, info, warn, error
	Format string // json, text
	Writer io.Writer
}

Options configures the logger. Empty fields fall back to defaults: info level, json format, stdout.

Jump to

Keyboard shortcuts

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