fastlog

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package fastlog configures structured slog handlers.

Environment defaults emit JSON events to stderr. The package registers stdout and stderr stream handlers by default:

import "github.com/InsideGallery/core/fastlog"

New code should prefer NewLoggerWithRegistry, SetupDefaultLogger, and InstallDefaultLogger so handler registries and process-wide defaults have explicit ownership.

Compatibility: NewLogger and SetupDefaultLog remain available for existing package-level wiring. File logging is available only when consumers import fastlog/handlers/logfile for legacy compatibility.

Index

Constants

View Source
const EnvPrefix = "LOG"
View Source
const (
	Separator = ":"
)

Variables

This section is empty.

Functions

func NewLogger deprecated added in v1.1.0

func NewLogger(cfg *Config, m ...slogmulti.Middleware) (*slog.Logger, error)

NewLogger creates a logger from explicit config and the compatibility handler registry.

Deprecated: use SetupDefault for standard bootstrapping or NewLoggerWithRegistry when callers need bespoke wiring.

func NewLoggerWithRegistry added in v1.1.0

func NewLoggerWithRegistry(
	cfg *Config,
	registry *handlers.Registry,
	m ...slogmulti.Middleware,
) (*slog.Logger, error)

NewLoggerWithRegistry creates a logger from explicit config and handler registry.

func SetupDefault added in v1.1.0

func SetupDefault(
	ctx context.Context,
	cfg *Config,
	m ...slogmulti.Middleware,
) (func() error, error)

SetupDefault creates and installs a process-wide logger from explicit config.

func SetupDefaultLog deprecated

func SetupDefaultLog(m ...slogmulti.Middleware)

SetupDefaultLog reads logger config from environment and installs it as slog default.

Deprecated: use GetConfigFromEnv plus SetupDefault so callers can handle errors and close the logger.

Types

type Config

type Config struct {
	Outputs         []string   `env:"_OUTPUTS" envDefault:"stderr:json"`
	Level           slog.Level `env:"_LEVEL" envDefault:"INFO"`
	Caller          bool       `env:"_CALLER" envDefault:"true"`
	ErrorFormatting bool       `env:"_ERROR_FORMATING" envDefault:"false"`
}

func GetConfigFromEnv

func GetConfigFromEnv() (*Config, error)

func (*Config) GetHandler deprecated

func (c *Config) GetHandler(m ...slogmulti.Middleware) (slog.Handler, error)

GetHandler returns a slog handler from the package-level compatibility registry.

Deprecated: use GetHandlerFromRegistry with an explicit handler registry.

func (*Config) GetHandlerFromRegistry added in v1.1.0

func (c *Config) GetHandlerFromRegistry(registry *handlers.Registry, m ...slogmulti.Middleware) (slog.Handler, error)

GetHandlerFromRegistry returns a slog handler from an explicit handler registry.

type DefaultLoggerHandle added in v1.1.0

type DefaultLoggerHandle struct {
	// contains filtered or unexported fields
}

DefaultLoggerHandle restores a previous slog default logger.

func InstallDefaultLogger added in v1.1.0

func InstallDefaultLogger(logger *slog.Logger) *DefaultLoggerHandle

InstallDefaultLogger installs a process-wide slog default with a restore path.

Use InstallDefaultLogger when callers need bespoke logger wiring. SetupDefault is the standard bootstrap.

func SetupDefaultLogger added in v1.1.0

func SetupDefaultLogger(cfg *Config, m ...slogmulti.Middleware) (*DefaultLoggerHandle, error)

SetupDefaultLogger creates and installs a process-wide logger from explicit config.

func (*DefaultLoggerHandle) Close added in v1.1.0

func (h *DefaultLoggerHandle) Close() error

Close restores the previous process-wide slog default and flushes the installed handler.

Directories

Path Synopsis
Package all imports every in-tree fastlog handler so each handler registers with the default fastlog handler registry through its init hook.
Package all imports every in-tree fastlog handler so each handler registers with the default fastlog handler registry through its init hook.
logfile
Package logfile provides a legacy opt-in slog writer that appends log events to a local file.
Package logfile provides a legacy opt-in slog writer that appends log events to a local file.
nop

Jump to

Keyboard shortcuts

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