logger

package
v0.0.0-...-2b7dcb4 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: BSD-2-Clause Imports: 5 Imported by: 53

Documentation

Overview

package logger is a package that provides a structured logger that's context.Context aware.

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogLevel = INFO
View Source
var DefaultLogger = New(log.New(os.Stdout, "[default] ", log.LstdFlags), DefaultLogLevel)

Functions

func Debug

func Debug(ctx context.Context, msg string, pairs ...interface{})

func Error

func Error(ctx context.Context, msg string, pairs ...interface{})

func FormatLevel

func FormatLevel(level Level) string

func Info

func Info(ctx context.Context, msg string, pairs ...interface{})

func Warn

func Warn(ctx context.Context, msg string, pairs ...interface{})

func WithLogger

func WithLogger(ctx context.Context, l Logger) context.Context

WithLogger inserts a log.Logger into the provided context.

Types

type Level

type Level int
const (
	OFF Level = iota
	ERROR
	WARN
	INFO
	DEBUG
)

func ParseLevel

func ParseLevel(lvl string) Level

type Logger

type Logger interface {
	Debug(msg string, pairs ...interface{})
	Info(msg string, pairs ...interface{})
	Warn(msg string, pairs ...interface{})
	Error(msg string, pairs ...interface{})
	With(pairs ...interface{}) Logger
}

Logger represents a structured leveled logger.

func FromContext

func FromContext(ctx context.Context) (Logger, bool)

FromContext returns a log.Logger from the context.

func New

func New(l *log.Logger, ll Level) Logger

New wraps the log.Logger to implement the Logger interface.

Jump to

Keyboard shortcuts

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