blip

package module
v0.0.0-...-1f0ca49 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: MIT Imports: 10 Imported by: 0

README

Blip

Blip is a logger.

import "github.com/localhots/blip"
import "github.com/localhots/blip/ctx/log"

log.Setup(blip.DefaultConfig())

log.Debug(ctx, "Callback received", log.F{
	"device_unique_id": "G4000E-1000-F",
	"task_id":          123456,
	"status":           "success",
	"template_name":    "index.tpl",
})

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DurationPrecision = time.Millisecond
	TimeFormat        = time.RFC3339
)

Functions

func WithContext

func WithContext(ctx context.Context, fields F) context.Context

Types

type Config

type Config struct {
	Level           Level
	Output          io.Writer
	Time            bool
	TimeFormat      string
	TimePrecision   time.Duration
	Color           bool
	MinMessageWidth int
	SortFields      bool
	StackTraceLevel Level
	StackTraceSkip  int
}

func DefaultConfig

func DefaultConfig() Config

type F

type F map[string]any

F is a convenient alias for a map of fields.

func FromContext

func FromContext(ctx context.Context) F

type Field

type Field struct {
	Key   string
	Value any
}

Field is a key-value pair that is used to add structured data to log entries.

type Level

type Level int
const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelPanic
	LevelFatal
)

type Logger

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

func New

func New(cfg Config) *Logger

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, msg string, fields ...F)

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, msg string, fields ...F)

func (*Logger) Fatal

func (l *Logger) Fatal(ctx context.Context, msg string, fields ...F)

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, msg string, fields ...F)

func (*Logger) Panic

func (l *Logger) Panic(ctx context.Context, msg string, fields ...F)

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, msg string, fields ...F)

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, msg string, fields ...F)

Directories

Path Synopsis
ctx
log
noctx
log

Jump to

Keyboard shortcuts

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