log

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package log provides Runa log primitives.

Index

Constants

View Source
const (
	DefaultName = "default"
	HTTP        = "http"
	Error       = "error"
	Audit       = "audit"
	Queue       = "queue"
	Schedule    = "schedule"
	Task        = "task"
	ORM         = "orm"
	Redis       = "redis"
)

Variables

This section is empty.

Functions

func Channel added in v0.1.1

func Channel(app any, name string) *slog.Logger

Channel returns a named logger from the supplied app, provider context, registry, or the process default registry.

func Fanout

func Fanout(handlers ...slog.Handler) slog.Handler

Fanout sends records to multiple handlers.

func Provider

func Provider(options ...ProviderOption) runaprovider.Provider

func ServiceName

func ServiceName(name string) string

ServiceName returns the DI service name for a log channel.

Types

type Info

type Info struct {
	Name    string
	Outputs int
	Default bool
}

Info stores one log channel snapshot.

type Option

type Option func(*Options)

Option configures log output options.

func Attr

func Attr(key string, value any) Option

Attr appends a static handler attr.

func Color

func Color(enabled bool) Option

Color enables or disables colors for pretty output.

func JSON

func JSON() Option

JSON uses JSON log format.

func Level

func Level(level slog.Leveler) Option

Level sets minimum log level.

func Pretty

func Pretty() Option

Pretty uses colored console log format.

func Source

func Source(enabled bool) Option

Source enables source location.

func Text

func Text() Option

Text uses text log format.

type Options

type Options struct {
	Level   slog.Leveler
	Format  string
	Source  bool
	Attrs   []slog.Attr
	NoColor bool
}

Options configures a slog handler.

func BuildOptions

func BuildOptions(items ...Option) Options

BuildOptions resolves log output options.

type Output

type Output interface {
	Build(ctx context.Context, name string) (slog.Handler, error)
}

Output builds a slog handler for a channel.

func Console

func Console(options ...Option) Output

Console returns a stdout output.

func Discard

func Discard() Output

Discard returns a discard output.

func File

func File(path string, options ...Option) Output

File returns a plain file output.

func Handler

func Handler(handler slog.Handler) Output

Handler wraps an existing slog handler.

func Writer

func Writer(writer io.Writer, options ...Option) Output

Writer returns a writer output.

type OutputFunc

type OutputFunc func(context.Context, string) (slog.Handler, error)

OutputFunc adapts a function to Output.

func (OutputFunc) Build

func (fn OutputFunc) Build(ctx context.Context, name string) (slog.Handler, error)

Build builds a slog handler.

type ProviderOption

type ProviderOption func(*provider)

func Register

func Register(name string, outputs ...Output) ProviderOption

type Registry

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

Registry stores named log channel configuration and instances.

func Default

func Default() *Registry

Default returns the default app log registry.

func New

func New() *Registry

New creates a registry.

func (*Registry) Build

func (registry *Registry) Build(ctx context.Context, name string) *slog.Logger

Build builds a named logger.

func (*Registry) Close

func (registry *Registry) Close(ctx context.Context) error

Close closes closeable log outputs once.

func (*Registry) Get

func (registry *Registry) Get(name string) *slog.Logger

Get returns a named logger.

func (*Registry) Info

func (registry *Registry) Info() []Info

Info returns configured log channel snapshots.

func (*Registry) Set

func (registry *Registry) Set(name string, outputs ...Output)

Set registers a named logger channel.

func (*Registry) Shutdown

func (registry *Registry) Shutdown(ctx context.Context) error

Shutdown closes closeable log outputs when managed by DI.

Jump to

Keyboard shortcuts

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