logger

package
v0.0.0-...-e5775fa Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logger describes interfaces for a logger.Logger and other support elements

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FxModule

func FxModule() fx.Option

Types

type Configuration

type Configuration struct {
	ServiceName string     `required:"true" envconfig:"SVC_NAME"`
	LogLevel    string     `required:"false" envconfig:"LOG_LEVEL" default:"info"`
	LoggerType  LoggerType `required:"false" envconfig:"LOGGER_TYPE" default:"zap"`
}

type LogFields

type LogFields map[string]any

type LogLevel

type LogLevel int
const (
	LogLevelDebug LogLevel = iota - 1
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelCritical
)

func ParseLevel

func ParseLevel(level string) LogLevel

type Logger

type Logger interface {
	Enabled(level int) bool

	WithContext(ctx context.Context) Logger
	WithFields(fields LogFields) Logger
	WithKeysAndValues(keysAndValues ...any) Logger

	IsLevelEnabled(level LogLevel) bool

	// Context-aware methods
	DebugContext(ctx context.Context, msg string, args ...any)
	InfoContext(ctx context.Context, msg string, args ...any)
	WarnContext(ctx context.Context, msg string, args ...any)
	ErrorContext(ctx context.Context, msg string, args ...any)
	CriticalContext(ctx context.Context, msg string, args ...any)

	// Non-context methods
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
	Critical(msg string, args ...any)
}

func New

func New(opts ...Option) Logger

New creates a new logger with optional configuration

type LoggerType

type LoggerType string

LoggerType defines the type of logger implementation

const (
	ZapLogger  LoggerType = "zap"
	SlogLogger LoggerType = "slog"
)

type Option

type Option func(*config)

Option defines a function that can modify the logger configuration

func WithLevel

func WithLevel(level LogLevel) Option

WithLevel sets the log level

func WithType

func WithType(loggerType LoggerType) Option

WithType sets the logger type

Directories

Path Synopsis
Package loggertest ...
Package loggertest ...

Jump to

Keyboard shortcuts

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