logging

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MPL-2.0 Imports: 4 Imported by: 1 module, 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.

Documentation

Overview

Package logging provides a structured logging interface compatible with slog levels and common logging utilities for the MindTrial application.

Index

Constants

View Source
const (
	LevelTrace = slog.Level(-8) // most verbose
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError // least verbose
)

Common logging levels for structured logging.

View Source
const UnknownLogValue = "<unknown>"

UnknownLogValue is the placeholder text used when logging nil or unknown values.

Variables

This section is empty.

Functions

func FormatLogInt64

func FormatLogInt64(value *int64) string

FormatLogInt64 formats an int64 pointer value for logging. If the pointer is nil, it returns a placeholder value.

func FormatLogText

func FormatLogText(lines []string) string

FormatLogText formats a slice of strings for logging with tab indentation and double-newline separation. If the slice is empty, it returns a tab-indented placeholder value.

Types

type Logger

type Logger interface {
	// Message logs a message at the specified level with optional format arguments.
	Message(ctx context.Context, level slog.Level, msg string, args ...any)

	// Error logs an error at the specified level with optional format arguments.
	Error(ctx context.Context, level slog.Level, err error, msg string, args ...any)

	// WithContext returns a new Logger that appends the specified context to the existing prefix.
	// This allows for hierarchical logging where components can add their context
	// without affecting the original logger instance. Each call extends the prefix chain.
	WithContext(context string) Logger
}

Logger defines a generic logging interface following slog style with log levels. It provides structured logging capabilities for both regular messages and error handling.

type StructuredError added in v0.15.0

type StructuredError interface {
	error
	LogFields() map[string]any
}

StructuredError is an interface that can be implemented by error types to provide custom fields for structured logging.

Jump to

Keyboard shortcuts

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