logging

package
v0.0.0-...-e40ec6d Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: EUPL-1.2 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OptionWithDoubleLine

func OptionWithDoubleLine(l *LoggerImpl) error

func WithLogger

func WithLogger(ctx context.Context, logger Logger) context.Context

WithLogger adds a logger to the context

Types

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field represents a key-value pair for structured logging

type Logger

type Logger interface {
	Debug(ctx context.Context, msg string, fields ...Field)
	Info(ctx context.Context, msg string, fields ...Field)
	Warning(ctx context.Context, msg string, fields ...Field)
	Error(ctx context.Context, msg string, fields ...Field)
	Debugf(ctx context.Context, format string, args ...any)
	Infof(ctx context.Context, format string, args ...any)
	Warningf(ctx context.Context, format string, args ...any)
	Errorf(ctx context.Context, format string, args ...any)
	WithName(name string) Logger
	WithService(service string) Logger
	WithLaw(law string) Logger
	WithField(key string, value any) Logger
	WithFields(fields ...Field) Logger
	WithIndent() Logger
	IndentBlock(ctx context.Context, msg string, fn func(context.Context) error, op ...Options) error
}

Logger interface defines the logging methods

func FromContext

func FromContext(ctx context.Context) Logger

FromContext retrieves the logger from context

type LoggerImpl

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

LoggerImpl is the concrete implementation of Logger

func New

func New(name string, output io.Writer, level logrus.Level) *LoggerImpl

New creates a new logger instance

func (*LoggerImpl) Debug

func (l *LoggerImpl) Debug(ctx context.Context, msg string, fields ...Field)

Debug logs a debug message with indentation

func (*LoggerImpl) Debugf

func (l *LoggerImpl) Debugf(ctx context.Context, format string, args ...any)

Debugf logs a debug message with indentation

func (*LoggerImpl) Error

func (l *LoggerImpl) Error(ctx context.Context, msg string, fields ...Field)

Error logs an error message with indentation

func (*LoggerImpl) Errorf

func (l *LoggerImpl) Errorf(ctx context.Context, format string, args ...any)

Errorf logs a debug message with indentation

func (*LoggerImpl) IndentBlock

func (l *LoggerImpl) IndentBlock(ctx context.Context, msg string, fn func(context.Context) error, options ...Options) error

IndentBlock executes a function within an indented logging block

func (*LoggerImpl) Info

func (l *LoggerImpl) Info(ctx context.Context, msg string, fields ...Field)

Info logs an info message with indentation

func (*LoggerImpl) Infof

func (l *LoggerImpl) Infof(ctx context.Context, format string, args ...any)

Infof logs a debug message with indentation

func (*LoggerImpl) Warning

func (l *LoggerImpl) Warning(ctx context.Context, msg string, fields ...Field)

Warning logs a warning message with indentation

func (*LoggerImpl) Warningf

func (l *LoggerImpl) Warningf(ctx context.Context, format string, args ...any)

Warningf logs a debug message with indentation

func (*LoggerImpl) WithField

func (l *LoggerImpl) WithField(key string, value interface{}) Logger

WithField returns a new logger with an additional field

func (*LoggerImpl) WithFields

func (l *LoggerImpl) WithFields(fields ...Field) Logger

WithFields returns a new logger with additional fields

func (*LoggerImpl) WithIndent

func (l *LoggerImpl) WithIndent() Logger

WithIndent returns a new logger with increased indentation level

func (*LoggerImpl) WithIndentValue

func (l *LoggerImpl) WithIndentValue(v int) Logger

WithIndent returns a new logger with increased indentation level

func (*LoggerImpl) WithLaw

func (l *LoggerImpl) WithLaw(law string) Logger

func (*LoggerImpl) WithName

func (l *LoggerImpl) WithName(name string) Logger

func (*LoggerImpl) WithService

func (l *LoggerImpl) WithService(service string) Logger

type Options

type Options func(l *LoggerImpl) error

type TreeChar

type TreeChar string
const (
	PipeSingle   TreeChar = "│  "
	BranchSingle TreeChar = "├──"
	LeafSingle   TreeChar = "└──"

	PipeDouble   TreeChar = "║  "
	BranchDouble TreeChar = "║──"
	LeadDouble   TreeChar = "╚══"

	Space TreeChar = "   "
)

Jump to

Keyboard shortcuts

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