logger

package
v0.0.0-...-9be77c3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package logger provides support for initializing the log system.

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

func NewStdLogger

func NewStdLogger(logger *Logger, level Level) *log.Logger

NewStdLogger returns a standard library Logger that wraps the slog Logger.

Types

type EventFn

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

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

type Events

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

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(w io.Writer, minLevel Level, serviceName string, traceIDFn TraceIDFn) *Logger

New constructs a new log for application use.

func NewWithEvents

func NewWithEvents(w io.Writer, minLevel Level, serviceName string, traceIDFn TraceIDFn, events Events) *Logger

NewWithEvents constructs a new log for application use with events.

func NewWithHandler

func NewWithHandler(h slog.Handler) *Logger

NewWithHandler returns a new log for application use with the underlying handler.

func (*Logger) Debug

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

Debug logs at LevelDebug with the given context.

func (*Logger) Debugc

func (log *Logger) Debugc(ctx context.Context, caller int, msg string, args ...any)

Debugc logs the information at the specified call stack position.

func (*Logger) Error

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

Error logs at LevelError with the given context.

func (*Logger) Errorc

func (log *Logger) Errorc(ctx context.Context, caller int, msg string, args ...any)

Errorc logs the information at the specified call stack position.

func (*Logger) Info

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

Info logs at LevelInfo with the given context.

func (*Logger) Infoc

func (log *Logger) Infoc(ctx context.Context, caller int, msg string, args ...any)

Infoc logs the information at the specified call stack position.

func (*Logger) Warn

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

Warn logs at LevelWarn with the given context.

func (*Logger) Warnc

func (log *Logger) Warnc(ctx context.Context, caller int, msg string, args ...any)

Warnc logs the information at the specified call stack position.

type Record

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

Record represents the data that is being logged.

type TraceIDFn

type TraceIDFn func(ctx context.Context) string

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

Jump to

Keyboard shortcuts

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