logging

package
v0.0.0-...-a93a156 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Console

func Console(ctx context.Context, monitoring bool) *zap.Logger

func LogDecorator

func LogDecorator[F any](fn F) F

LogDecorator é uma função genérica que aceita uma função `fn` e retorna uma nova função que loga os detalhes da execução de `fn`, incluindo argumentos, valor de retorno, e tempo de execução.

Exemplo de uso: ```go

func soma(a, b int) int {
    return a + b
}

soma = LogDecorator(soma) soma(1, 2) // Saída: "Iniciando a execução de main.soma com os argumentos: [1 2]" e "Função main.soma executada em 1.5µs com o retorno: [3]" ```

Exemplo de uso com função anônima: ```go

fn := LogDecorator(func(a, b int) int {
    return a + b
})

fn(1, 2) // Saída: "Iniciando a execução de main.func1 com os argumentos: [1 2]" e "Função main.func1 executada em 1.5µs com o retorno: [3]" ```

Exemplo de uso com metodos de struct: ```go type Soma struct{}

func (s Soma) Soma(a, b int) int {
    return a + b
}

func SomaAdapter(s Soma) func(int, int) int {
	return func(a, b int) int {
		return s.Soma(a, b)
	}
}

func main() {
	soma := Soma{}

	somaFunc := AddAdapter(soma) // Transforma o método `Add` em uma função adaptada.

	decoratedSoma := LogDecorator(somaFunc) // Aplica o `LogDecorator` à função adaptada.

	result := decoratedSoma(5, 3) // Usa a função decorada.
}

func LogMiddleware

func LogMiddleware(ctx context.Context, monitoring bool, f interface{}) interface{}

func RegisterFieldForContextLog

func RegisterFieldForContextLog[T any](logKey string, contextKey any, valueMarshaller func(string, T) zapcore.Field)

func SetLevel

func SetLevel(level string)

Types

type FuncWrapper

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

func NewFuncWrapper

func NewFuncWrapper(fn interface{}) *FuncWrapper

func (*FuncWrapper) Invoke

func (f *FuncWrapper) Invoke(args ...interface{}) []reflect.Value

type Loggable

type Loggable interface {
	Invoke(args []reflect.Value) []reflect.Value
}

type Logger

type Logger interface {
	SetLevel(level string)
	Console() *zap.Logger
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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