logkit

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 5 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 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 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. This Option modifies the 'withJSON' field of the Options struct. Example: options := &Options{} opt := WithJSON() opt(options) After applying the WithJSON Option, options.withJSON field will be set to true.

func WithLevel

func WithLevel(level slog.Level) Option

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

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