slog

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 6 Imported by: 2

README

template

Documentation

Overview

Package slog provides a structured logging system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

Logger represents a structured logger.

func NewLogger

func NewLogger(opts ...Option) *Logger

NewLogger returns a new Logger instance with the given options.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the logger.

func (*Logger) Context

func (l *Logger) Context() context.Context

Context returns the context associated with the logger.

func (*Logger) Log

func (l *Logger) Log(level log.Level, keyvals ...interface{}) error

Log logs a message at the given level with the given key-value pairs.

type Option

type Option = func(log *Logger)

Option is a function that configures a Logger instance.

func WithContext

func WithContext(ctx context.Context) Option

WithContext returns an Option that sets the context for the logger.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger returns an Option that sets the underlying slog.Logger instance.

func WithMessageKey

func WithMessageKey(key string) Option

WithMessageKey returns an Option that sets the message key for the logger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳