wdlogger

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: GPL-3.0 Imports: 2 Imported by: 1

README

Wrapped Logger

The package supplies adapters to various logging libraries. This allows the application not to be tied to any particular library, but, if necessary, to painlessly replace one with another.

This is implemented due to the fact that your application is tied to this wrapper, and not a specific library. The wrapper, in turn, has a standardized logging interface that adapts to a specific library.

When there is a need to try some new logging library, you can use a ready-made adapter or write your own, which is much easier than rewriting the entire application.

Documentation

Available adapters

Features of the wdlogger

  • zap adapter is able to output logs in the GELF format (others will have this opportunity in the future)

Project status

It is currently under experimental development and is used in my own projects for convenience, but this does not prevent you from proposing your own changes if you wish.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithFields

func WithFields(ctx context.Context, fields ...Field) context.Context

Types

type CtxLogger

type CtxLogger interface {
	DebugCtx(ctx context.Context, msg string, fields ...Field)
	InfoCtx(ctx context.Context, msg string, fields ...Field)
	WarnCtx(ctx context.Context, msg string, fields ...Field)
	ErrorCtx(ctx context.Context, msg string, fields ...Field)
	PanicCtx(ctx context.Context, msg string, fields ...Field)
	FatalCtx(ctx context.Context, msg string, fields ...Field)
}

CtxLogger по сути тот же интерфейс Logger, только методы CtxLogger первым аргументом принимают контекст, где находятся поля логгера

type Field

type Field struct {
	Key   string
	Value any
}

Field Поле context-based логгера

func ExtractFields

func ExtractFields(ctx context.Context, fields ...Field) []Field

func NewBoolField

func NewBoolField(key string, value bool) Field

func NewErrorField

func NewErrorField(key string, value error) Field

func NewFloat64Field

func NewFloat64Field(key string, value float64) Field

func NewInt64Field

func NewInt64Field(key string, value int64) Field

func NewIntField

func NewIntField(key string, value int) Field

func NewStringField

func NewStringField(key string, value string) Field

func NewTimeField

func NewTimeField(key string, value time.Time) Field

type Logger

type Logger interface {
	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Warn(msg string, fields ...Field)
	Error(msg string, fields ...Field)
	Panic(msg string, fields ...Field)
	Fatal(msg string, fields ...Field)
}

Directories

Path Synopsis
examples
zap command
wrappers

Jump to

Keyboard shortcuts

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