logger

package
v0.0.0-...-8e8e47b Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, args ...any)

func DebugFn

func DebugFn(ctx context.Context, fn LogFn)

func Debugf

func Debugf(ctx context.Context, format string, args ...any)

func Error

func Error(ctx context.Context, args ...any)

func ErrorFn

func ErrorFn(ctx context.Context, fn LogFn)

func Errorf

func Errorf(ctx context.Context, format string, args ...any)

func Fatal

func Fatal(ctx context.Context, args ...any)

func FatalFn

func FatalFn(ctx context.Context, fn LogFn)

func Fatalf

func Fatalf(ctx context.Context, format string, args ...any)

func Info

func Info(ctx context.Context, args ...any)

func InfoFn

func InfoFn(ctx context.Context, fn LogFn)

func Infof

func Infof(ctx context.Context, format string, args ...any)

func MustConfigure

func MustConfigure(opts ...ConfigOption)

MustConfigure parses the logger conf and configures the application logger.

func Panic

func Panic(ctx context.Context, args ...any)

func PanicFn

func PanicFn(ctx context.Context, fn LogFn)

func Panicf

func Panicf(ctx context.Context, format string, args ...any)

func SetFormatter

func SetFormatter(f logFormatterType)

SetFormatter sets a custom log formatter function. It replaces the default log formatter with the provided one.

func SetLevel

func SetLevel(level LogLevel)

SetLevel sets the application log level.

func SetOutput

func SetOutput(out io.Writer)

func Trace

func Trace(ctx context.Context, args ...any)

func TraceFn

func TraceFn(ctx context.Context, fn LogFn)

func Tracef

func Tracef(ctx context.Context, format string, args ...any)

func Warn

func Warn(ctx context.Context, args ...any)

func WarnFn

func WarnFn(ctx context.Context, fn LogFn)

func Warnf

func Warnf(ctx context.Context, format string, args ...any)

func WithField

func WithField(ctx context.Context, key string, value any) context.Context

func WithFields

func WithFields(ctx context.Context, fieldsToAdd map[string]any) context.Context

Types

type Config

type Config struct {
	LogLevel string `config_format:"snake" config_default:"INFO" validate:"required,oneof=ERROR WARN INFO DEBUG TRACE"`
}

Config contains the values needed to configure the logger.

type ConfigOption

type ConfigOption func(*loggerConfig)

ConfigOption sets values on the loggerConfig.

func WithConfigProvider

func WithConfigProvider(provider func() (*Config, error)) ConfigOption

WithConfigProvider sets the provider for the config.Logger.

func WithOutputProvider

func WithOutputProvider(provider func() (io.Writer, error)) ConfigOption

WithOutputProvider sets the logger output.

type LogFn

type LogFn func() []any

type LogLevel

type LogLevel int

LogLevel represents the various log levels.

const (
	LevelError LogLevel = iota
	LevelWarn
	LevelInfo
	LevelDebug
	LevelTrace
)

func GetLevel

func GetLevel() LogLevel

GetLevel returns the applications log level.

func ParseLevel

func ParseLevel(level string) (LogLevel, error)

ParseLevel parses a string into a LogLevel.

func (LogLevel) MarshalText

func (l LogLevel) MarshalText() ([]byte, error)

MarshalText serializes the LogLevel into text.

func (LogLevel) String

func (l LogLevel) String() string

String converts a LogLevel to its string representation.

func (*LogLevel) UnmarshalText

func (l *LogLevel) UnmarshalText(text []byte) error

UnmarshalText deserializes text into a LogLevel.

Jump to

Keyboard shortcuts

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