Documentation
¶
Overview ¶
Package logging provides execution-scoped structured logging.
Index ¶
- func Channels(ctx context.Context, names ...string) (*slog.Logger, error)
- func ErrorCategory(err error) string
- func FromContext(ctx context.Context) *slog.Logger
- func New(output io.Writer, options Options) (*slog.Logger, error)
- func Select(logger *slog.Logger, names ...string) (*slog.Logger, error)
- func WithLogger(ctx context.Context, logger *slog.Logger) context.Context
- type Channel
- type Config
- type Driver
- type FileMode
- type Format
- type Manager
- type OTLPOptions
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Channels ¶
Channels selects outputs from the context logger, preserving With/WithGroup fields. A logger created with New or an unrelated handler has no named channels.
func ErrorCategory ¶
ErrorCategory returns a bounded diagnostic category without exposing error text. It recognizes wrapped causes. It is for reporting, not retry or business policy.
func New ¶
New creates an independent logger; it does not replace slog.Default or own the writer. Tint is intended for development; JSON remains the default.
Types ¶
type Channel ¶
type Channel struct {
Driver string
Path string
Options Options
// FileMode selects single-file (default) or daily output for the file driver.
FileMode FileMode
// KeepDays retains this many UTC calendar days, including today, in daily
// mode. Zero keeps all files. Single-file mode requires zero.
KeepDays int
// OTLP configures the otlp driver. Other drivers do not use it.
OTLP OTLPOptions
}
Channel configures one output. Open resolves relative file paths against the working directory once, including channels selected later.
type Config ¶
type Config struct {
Default []string
Channels map[string]Channel
Drivers map[string]Driver
// WrapHandler optionally decorates each opened channel once, before deriving
// scoped loggers. It must preserve Enabled, support concurrent use and return
// a non-nil handler. The decorator borrows the output; Manager owns its lifetime.
WrapHandler func(name string, handler slog.Handler) slog.Handler
// OnError reports synchronous output failures, which slog.Logger otherwise discards.
// Asynchronous OTLP export failures use independent stderr diagnostics.
// It must be concurrency-safe and must not log back through these channels.
// Nil reports failures directly to stderr.
OnError func(context.Context, string, error)
}
Config defines named channels and the default fanout. Drivers adds custom drivers without global registration. Channels and Drivers are borrowed during Open.
type Driver ¶
Driver opens a concurrency-safe handler and optionally an owned resource. On failure it must clean up its partial initialization. Borrowed resources must return a nil closer. Handlers must obey the slog.Handler ownership contract. A closer implementing Shutdown(context.Context) error receives the manager's shutdown context; otherwise the manager calls Close.
type FileMode ¶
type FileMode string
FileMode selects how the file driver names and rotates its output.
type Format ¶
type Format string
Format selects a slog handler while preserving its environment/JSON spelling.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns opened channel resources. Loggers support concurrent use; Close must run after their users finish. It never changes slog.Default.
func Open ¶
Open validates all definitions and opens only default channels. Other channels open when explicitly selected. A failed selection can be retried. It closes acquired resources on failure. File output appends, creates directories with mode 0750 and new files with mode 0600. Daily files optionally expire by date; neither mode fsyncs each record.
type OTLPOptions ¶
type OTLPOptions struct {
Endpoint string
ServiceName string
Environment string
ExportTimeout time.Duration
ShutdownTimeout time.Duration
}
OTLPOptions configures asynchronous OTLP/HTTP log delivery. Endpoint is the full URL including /v1/logs. Put backend credentials in a collector, not this URL. Zero timeouts use five seconds for export and three seconds for shutdown. An empty ServiceName uses unknown_service for standalone callers.
func (OTLPOptions) Validate ¶
func (o OTLPOptions) Validate() error