logger

package
v0.0.0-...-29e199f Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package logger defines the logging utilities for the signare.

nolint: loggercheck

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterLogger

func RegisterLogger(options Options)

RegisterLogger for the application with the provided options.

Types

type Level

type Level string

Level represents the importance or severity of a log event.

const (
	LevelInfo  Level = "INFO"
	LevelWarn  Level = "WARN"
	LevelError Level = "ERROR"
	LevelDebug Level = "DEBUG"
)

func ToLevel

func ToLevel(level string) (*Level, bool)

ToLevel maps a string to its corresponding Level returning false if it's not defined.

type LogKey

type LogKey string

type Logger

type Logger interface {
	// WithArguments injects extra arguments to the log entry
	WithArguments(args ...any) Logger
	// Info creates a log entry with LevelInfo
	Info(msg string)
	// Infof creates a formatted log entry with LevelInfo
	Infof(format string, args ...any)
	// Debug creates a log entry with LevelDebug
	Debug(msg string)
	// Debugf creates a formatted log entry with LevelDebug
	Debugf(format string, args ...any)
	// Warn creates a log entry with LevelWarn
	Warn(msg string)
	// Warnf creates a formatted log entry with LevelWarn
	Warnf(format string, args ...any)
	// Error creates a log entry with LevelError
	Error(msg string)
	// Errorf creates a formatted log entry with LevelError
	Errorf(format string, args ...interface{})
}

Logger defines the functionality to log with different levels in the application.

func LogEntry

func LogEntry(ctx context.Context) Logger

LogEntry returns a new Logger

type Options

type Options struct {
	// Level the log level
	Level *Level
	// LogOutput where the logs are written to
	LogOutput io.Writer
	// CtxKeysRegistry defines which keys from the context, if present, will be logged as a default attribute.
	CtxKeysRegistry map[entities.ContextKey]LogKey
}

Options configures a Logger.

type Tracer

type Tracer interface {
	// AddProperty allows the inclusion of permanent properties to the Tracer's namespace object.
	AddProperty(key string, value any)
	// Trace creates a log entry with LevelInfo containing the tracer's object.
	Trace(msg string)
	// TraceWithData creates a log entry with LevelInfo containing the tracer's object.
	// The data arguments are placed inside the tracer's namespace object.
	TraceWithData(msg string, data map[string]any)
	// Warn creates a log entry with LevelWarn containing the tracer's object.
	Warn(msg string)
	// WarnWithData creates a log entry with LevelWarn containing the tracer's object.
	// The data arguments are placed inside the tracer's namespace object.
	WarnWithData(msg string, data map[string]any)
	// Error creates a log entry with LevelError containing the tracer's object.
	// The message is placed outside the tracer's namespace object.
	Error(msg string)
	// Errorf creates a log entry with LevelError containing the tracer's object,
	// formatting the message using a format string and arguments provided.
	Errorf(format string, data ...interface{})
	// ErrorWithData creates a log entry with LevelError containing the tracer's object.
	// The message is placed outside the tracer's namespace object, while the data arguments are placed inside of it.
	ErrorWithData(msg string, data map[string]any)
	// Debug creates a log entry with LevelDebug containing the tracer's object.
	Debug(msg string)
	// Debugf creates a log entry with LevelDebug containing the tracer's object,
	// formatting the message using a format string and arguments provided.
	Debugf(format string, data ...interface{})
	// DebugWithData creates a log entry with LevelDebug containing the tracer's object.
	// The data arguments are placed inside the tracer's namespace object.
	DebugWithData(msg string, data map[string]any)
}

Tracer represents a logger with tracing capabilities. It allows the creation of a scoped tracing object with a specific namespace.

func NewTracer

func NewTracer(ctx context.Context) Tracer

NewTracer returns a new Tracer for the specified namespace.

Jump to

Keyboard shortcuts

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