logger

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelDebug = Level(slog.LevelDebug)
	LevelInfo  = Level(slog.LevelInfo)
	LevelWarn  = Level(slog.LevelWarn)
	LevelError = Level(slog.LevelError)
)

A set of possible logging levels.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventFn added in v0.0.5

type EventFn func(ctx context.Context, r Record)

EventFn is a function to be executed when configured against a log level.

type Events added in v0.0.5

type Events struct {
	Debug EventFn
	Info  EventFn
	Warn  EventFn
	Error EventFn
}

Events contains an assignment of an event function to a log level.

type Level added in v0.0.5

type Level slog.Level

Level represents different logging levels.

type Logger

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

Logger represents a logger for logging information.

func New

func New(serviceName string, opts ...Option) *Logger

New constructs a newLogger log for application use.

func (*Logger) Debug

func (log *Logger) Debug(ctx context.Context, msg string, args ...any)

Debug logs at LevelDebug with the given context.

func (*Logger) Error

func (log *Logger) Error(ctx context.Context, msg string, args ...any)

Error logs at LevelError with the given context.

func (*Logger) Info

func (log *Logger) Info(ctx context.Context, msg string, args ...any)

Info logs at LevelInfo with the given context.

func (*Logger) Warn added in v0.0.5

func (log *Logger) Warn(ctx context.Context, msg string, args ...any)

Warn logs at LevelWarn with the given context.

type Option added in v0.0.5

type Option func(o *options)

func WithConsoleWriter added in v0.0.5

func WithConsoleWriter() Option

func WithDebugEvent added in v0.0.5

func WithDebugEvent(fn EventFn) Option

func WithErrorEvent added in v0.0.5

func WithErrorEvent(fn EventFn) Option

func WithInfoEvent added in v0.0.5

func WithInfoEvent(fn EventFn) Option

func WithLogLevel added in v0.0.5

func WithLogLevel(lvl Level) Option

func WithTraceIDFn added in v0.0.5

func WithTraceIDFn(fn TraceIDFn) Option

func WithWarnEvent added in v0.0.5

func WithWarnEvent(fn EventFn) Option

func WithWriter added in v0.0.5

func WithWriter(w io.Writer) Option

type Record added in v0.0.5

type Record struct {
	Time       time.Time
	Message    string
	Level      Level
	Attributes map[string]any
}

Record represents the data that is being logged.

type TraceIDFn added in v0.0.5

type TraceIDFn func(ctx context.Context) string

TraceIDFn represents a function that can return the trace id from the specified context.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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