logger

package
v0.0.0-...-ccef063 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 8 Imported by: 19

README

Logger package

This package provides a simple logger interface and a default implementation.

Support loggers

  • Zap
  • Logrus
  • Slog (structured logger)

Documentation

Overview

Logger

Index

Constants

View Source
const (
	// Zap implementation
	Zap int = iota
	// Logrus implementation
	Logrus
)

Variables

View Source
var ErrInvalidLoggerInstance = errors.New("invalid logger instance")

ErrInvalidLoggerInstance is an error when logger instance is invalid

Functions

func NewStructLogger

func NewStructLogger(log Logger) (*slog.Logger, error)

Types

type Logger

type Logger interface {
	Fatal(msg string, fields ...field.Fields)
	FatalWithContext(ctx context.Context, msg string, fields ...field.Fields)

	Error(msg string, fields ...field.Fields)
	ErrorWithContext(ctx context.Context, msg string, fields ...field.Fields)

	Warn(msg string, fields ...field.Fields)
	WarnWithContext(ctx context.Context, msg string, fields ...field.Fields)

	Info(msg string, fields ...field.Fields)
	InfoWithContext(ctx context.Context, msg string, fields ...field.Fields)

	Debug(msg string, fields ...field.Fields)
	DebugWithContext(ctx context.Context, msg string, fields ...field.Fields)

	Get() any

	// Closer is the interface that wraps the basic Close method.
	io.Closer
}

Logger is our contract for the logger

func New

func New(loggerInstance int, cfg config.Configuration) (Logger, error)

New - return new an instance of logger

type StructLogger

type StructLogger struct {
	Logger
	slog.Handler
}

func (*StructLogger) Enabled

func (sl *StructLogger) Enabled(ctx context.Context, level slog.Level) bool

func (*StructLogger) Handle

func (sl *StructLogger) Handle(ctx context.Context, record slog.Record) error

func (*StructLogger) WithAttrs

func (sl *StructLogger) WithAttrs(_ []slog.Attr) slog.Handler

func (*StructLogger) WithGroup

func (sl *StructLogger) WithGroup(_ string) slog.Handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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