logger

package
v0.0.0-...-35aec58 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyField

func EmptyField() map[string]interface{}

Types

type Default

type Default struct{}

Default is a struct that wraps the default logger from the "log" package. It satisfied logger.ILogger interface and provides additional methods for logging with context and options.

It is used as a fallback logger when the zap logger is not available.

func NewDefault

func NewDefault() *Default

NewDefault creates a new instance of Default logger using Go's native logger.

func (*Default) Debug

func (d *Default) Debug(ctx context.Context, msg string, options ...Field)

func (*Default) Error

func (d *Default) Error(ctx context.Context, msg string, options ...Field)

func (*Default) Fatal

func (d *Default) Fatal(ctx context.Context, msg string, options ...Field)

func (*Default) GetInstance

func (d *Default) GetInstance() interface{}

func (*Default) Info

func (d *Default) Info(ctx context.Context, msg string, options ...Field)

func (*Default) Panic

func (d *Default) Panic(ctx context.Context, msg string, options ...Field)

func (*Default) Warn

func (d *Default) Warn(ctx context.Context, msg string, options ...Field)

type Field

type Field func() map[string]interface{}

Field is a function type that returns a map of string keys to interface{} values. It is used to provide additional metadata for logging. The function is expected to return a map where each key-value pair represents a field to be logged.

func WithError

func WithError(err error) Field

WithError creates an option that contains the error.

func WithField

func WithField(key string, value interface{}) Field

WithField creates an option that contains the key-value pair.

func WithFields

func WithFields(metadata map[string]interface{}) Field

WithFields creates an option that contains the metadata.

type ILogger

type ILogger interface {
	// GetInstance returns the underlying logger instance.
	GetInstance() interface{}
	// Debug logs a message at DebugLevel.
	Debug(ctx context.Context, msg string, fields ...Field)
	// Info logs a message at InfoLevel.
	Info(ctx context.Context, msg string, fields ...Field)
	// Warn logs a message at WarnLevel.
	Warn(ctx context.Context, msg string, fields ...Field)
	// Error logs a message at ErrorLevel.
	Error(ctx context.Context, msg string, fields ...Field)
	// Fatal logs a message at FatalLevel.
	Fatal(ctx context.Context, msg string, fields ...Field)
	// Panic logs a message at PanicLevel.
	Panic(ctx context.Context, msg string, fields ...Field)
}

Jump to

Keyboard shortcuts

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