log

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 11 Imported by: 5

Documentation

Index

Constants

View Source
const (
	EncodingText = "text"
	EncodingJSON = "json"
)

Variables

View Source
var (
	// Sane default logger setup
	Logger = slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
		AddSource: false,
		Level:     slog.LevelInfo,
	}))

	ErrUnknownLogLevel    = errors.New("unknown log level")
	ErrUnknownLogEncoding = errors.New("unknown log encoding")
)

Defaults

Functions

func Debug

func Debug(msg string, args ...interface{})

func Debugf

func Debugf(template string, args ...interface{})

func Error

func Error(msg string, args ...interface{})

func Errorf

func Errorf(template string, args ...interface{})

func Fatal

func Fatal(msg string, args ...interface{})

func Fatalf

func Fatalf(template string, args ...interface{})

func Info

func Info(msg string, args ...interface{})

func Infof

func Infof(template string, args ...interface{})

func InitLogger

func InitLogger(c *LoggerConfig) error

InitLogger loads a global logger based on a configuration

func LogSkip

func LogSkip(ctx context.Context, logger *slog.Logger, level slog.Level, skip int, msg string, args ...interface{})

func Panic

func Panic(msg string, args ...interface{})

func Panicf

func Panicf(template string, args ...interface{})

func ParseLogLevel

func ParseLogLevel(level string) (slog.Level, error)

ParseLogLevel is used to parse configuration options into a log level.

func Printf

func Printf(template string, args ...interface{})

func Println

func Println(msg string)

func ReplaceAttrTrimSource added in v1.0.4

func ReplaceAttrTrimSource(groups []string, a slog.Attr) slog.Attr

func TrimSource

func TrimSource(source string, parts int) string

func Warn

func Warn(msg string, args ...interface{})

func Warnf

func Warnf(template string, args ...interface{})

Types

type LoggerConfig

type LoggerConfig struct {
	Level    string `conf:"level"`
	Encoding string `conf:"encoding"`
	Color    bool   `conf:"color"` // Only valid for console encoding.
	Output   string `conf:"output"`
}

type Wrapper

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

Wrapper implements various useful log functions with the provided logger to fulfill interfaces.

func NewWrapper

func NewWrapper(logger *slog.Logger, level slog.Level) *Wrapper

func (*Wrapper) Printf

func (w *Wrapper) Printf(template string, args ...interface{})

Jump to

Keyboard shortcuts

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