logkit

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...Option) *slog.Logger

func NewNop added in v0.2.2

func NewNop() *slog.Logger

NewNop returns a new disabled logger that logs nothing.

func ParseLevel

func ParseLevel(lvl string) (slog.Level, error)

ParseLevel takes the string and tries to parse it to the Level.

Types

type Error

type Error string

Error represents package level error related to logging work.

const (
	// ErrParseLevel indicates that string given to function ParseLevel can't be parsed to Level.
	ErrParseLevel Error = "string can't be parsed as Level, use: `error`, `warn`, `info`, `debug`"
)

func (Error) Error

func (e Error) Error() string

type Option

type Option func(*Options)

Option represents a function that modifies the configuration options for the logging library.

func WithColor added in v0.2.2

func WithColor() Option

WithColor creates an Option that enables color formatting for log messages. Will not take effect ff WithJSON is applied.

func WithJSON

func WithJSON() Option

WithJSON creates an Option that enables JSON formatting for log messages. When this Option is applied, log messages will be formatted as JSON objects.

func WithLevel

func WithLevel(level slog.Level) Option

WithLevel changes the underlying logging level of slog.Logger to the given on.

func WithSource added in v0.2.2

func WithSource() Option

WithSource creates an Option that enables source code line number formatting for log messages. When this Option is applied, log messages will contain source code line number.

func WithTimeFormat added in v0.2.2

func WithTimeFormat(format string) Option

WithTimeFormat creates an Option that change the time formatting for log messages.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter changes the writer for each leveled loggers of StdLog to the given on.

type Options

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

Options represents the configuration options for the logging library.

Jump to

Keyboard shortcuts

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