logger

package
v0.0.0-...-67051ba Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 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 EventFunc

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

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

type Events

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

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, traceIDFunc TraceIDFunc) *Logger

New constructs a new log for application use.

func NewWithEvents

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

NewWithEvents constructs a new log for application use with events.

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 TraceIDFunc

type TraceIDFunc func(ctx context.Context) string

TraceIDFunc 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