slogtool

package module
v0.0.0-...-ac7d99e Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 7 Imported by: 0

README

slogtool

The convenient interface for working with slog

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogLevel

type LogLevel int

LogLevel represents the severity of the log message.

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
)

func ConvertLoggerMode

func ConvertLoggerMode(mode Mode) LogLevel

type Logger

type Logger interface {
	Info(description string, attributes ...any)
	Debug(description string, attributes ...any)
	Error(description string, err error, attributes ...any)
	Warn(description string, attributes ...any)
	WithOperation(operation string) Logger
	StringAttr(attribute string, value string) any
	AnyAttr(attribute string, value any) any
	With(attributes ...any) Logger
	LogAndReturnError(message string, err error, attributes ...any) error
}

Logger interface defines methods for structured logging.

type Mode

type Mode string
const (
	DevMode  Mode = "dev"
	ProdMode Mode = "prod"
)

func ParseMode

func ParseMode(mode string) Mode

func (Mode) String

func (m Mode) String() string

type Slogger

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

Slogger is an implementation of Logger interface using slog.

func InitLogger

func InitLogger(mode LogLevel, output string) *Slogger

InitLogger initializes a new logger instance based on the provided mode and output strings. It returns a pointer to the initialized Slogger.

If output is "stdout" or "stderr", it configures the logger for the specified log level to the respective standard output.

If output is a file path, it configures the logger to log to that file.

func (*Slogger) AnyAttr

func (l *Slogger) AnyAttr(attribute string, value any) any

AnyAttr returns an any type attribute for logging.

func (*Slogger) Debug

func (l *Slogger) Debug(description string, attributes ...any)

Debug logs a debug level message.

func (*Slogger) Error

func (l *Slogger) Error(description string, err error, attributes ...any)

Error logs an error level message with the error details.

func (*Slogger) Info

func (l *Slogger) Info(description string, attributes ...any)

Info logs an info level message.

func (*Slogger) LogAndReturnError

func (l *Slogger) LogAndReturnError(message string, err error, attributes ...any) error

func (*Slogger) StringAttr

func (l *Slogger) StringAttr(attribute string, value string) any

StringAttr returns a string attribute for logging.

func (*Slogger) Warn

func (l *Slogger) Warn(description string, attributes ...any)

Warn logs a warn level message.

func (*Slogger) With

func (l *Slogger) With(attributes ...any) Logger

With returns a new logger with the given attributes.

func (*Slogger) WithOperation

func (l *Slogger) WithOperation(operation string) Logger

WithOperation returns a new logger with the given operation name.

Jump to

Keyboard shortcuts

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