logx

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package logx is a simple logging lib that shows calling func line, info and provide context for tracing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error[T any](p T, extraInfos ...any) T

Error will log and return first parameter p1 Example 1: logs.Error(err) Example 2 with extra request info: logs.Error(err, logs.F("myRequest",req)) Example 3: logs.Error(errx.Wrap(errs.ErrUnauthorized, errs.ErrUserNotFound, err))

func Info

func Info[T any](p T, extraInfos ...any) T

Info will log and return first parameter p Example 1: logs.Info(err) Example 2 with extra request info: logs.Error(err, logs.F("myRequest",req)) Example 3: logs.Info(errx.Wrap(errs.ErrUnauthorized, errs.ErrUserNotFound, err), logs.F("myRequest",req))

func SetLogger

func SetLogger(ls ...ExternalLogger)

SetLogger will set external loggers. This should be set ONCE only.

func Warn

func Warn[T any](p T, extraInfos ...any) T

Warn will log and return first parameter p Example: logs.Warn(errx.Wrap(errs.ErrUnauthorized, errs.ErrUserNotFound, err), logs.F("myRequest",req))

Types

type ExternalLogger

type ExternalLogger interface {
	Info(ctx context.Context, v ...any)
	Warn(ctx context.Context, v ...any)
	Error(ctx context.Context, v ...any)
}

func NewLoggerLocal

func NewLoggerLocal() ExternalLogger

type Field

type Field struct {
	Name string
	Data any
}

Field for logging extra info with json format

func F

func F(name string, data any) Field

F returns Field for logging extraInfos

type LoggerLocal

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

func (LoggerLocal) Error

func (l LoggerLocal) Error(_ context.Context, v ...interface{})

func (LoggerLocal) Info

func (l LoggerLocal) Info(_ context.Context, v ...interface{})

func (LoggerLocal) Warn

func (l LoggerLocal) Warn(_ context.Context, v ...interface{})

Jump to

Keyboard shortcuts

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