log

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLogType = errors.New("invalid log type")

ErrInvalidLogType is error for invalid log type.

Functions

func HandlerFuncWithLog

func HandlerFuncWithLog(logger Logger, next http.HandlerFunc, middlewareConfig ...MiddlewareConfig) http.HandlerFunc

HandlerFuncWithLog is http handler func with log.

func HandlerWithLog

func HandlerWithLog(logger Logger, next http.Handler, middlewareConfig ...MiddlewareConfig) http.Handler

HandlerWithLog is http handler with log. Also includes error stack tracing feature if you use it.

func MiddlewareWithLog

func MiddlewareWithLog(logger Logger, middlewareConfig ...MiddlewareConfig) func(http.Handler) http.Handler

MiddlewareWithLog is http middleware that will log the request and response.

func StreamMiddlewareWithLog added in v0.7.0

func StreamMiddlewareWithLog(logger Logger, middlewareConfig ...MiddlewareConfig) grpc.StreamServerInterceptor

StreamMiddlewareWithLog is stream grpc middleware that will log the request and response. Todo: implement logger here.

func UnaryMiddlewareWithLog added in v0.7.0

func UnaryMiddlewareWithLog(logger Logger, middlewareConfig ...MiddlewareConfig) grpc.UnaryServerInterceptor

UnaryMiddlewareWithLog is unary grpc middleware that will log the request and response.

Types

type LogLevel

type LogLevel int8

LogLevel is level of log that will be printed. Will print level that is higher than your chosen one.

const (
	TraceLevel LogLevel = iota - 1
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
	PanicLevel
	Disabled
)

Available log level.

type LogType

type LogType int8

LogType is type for logging library.

const (
	NoLog LogType = iota
	BuiltIn
	Zerolog
	Logrus
	Zap
)

Available types for logging.

type Logger

type Logger interface {
	Trace(format string, args ...interface{})
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warn(format string, args ...interface{})
	Error(format string, args ...interface{})
	Fatal(format string, args ...interface{})
	Panic(format string, args ...interface{})

	// General log with key value.
	Log(fields map[string]interface{})
}

Logger is logging interface.

See usage example in example folder.

func New

func New(logType LogType, level LogLevel, jsonFormat bool, color bool) (Logger, error)

New to create new log client depends on the type. Color will not work in json format.

type MiddlewareConfig

type MiddlewareConfig struct {
	// Show request header.
	RequestHeader bool
	// Show request body.
	RequestBody bool
	// Show response header.
	ResponseHeader bool
	// Show response body.
	ResponseBody bool
	// Include query param in url path.
	QueryParam bool
	// Show error stack.
	Error bool
}

MiddlewareConfig is log config for middleware.

Directories

Path Synopsis
Package builtin is a wrapper of the built-in log package.
Package builtin is a wrapper of the built-in log package.
Package logrus is a wrapper of the original "github.com/sirupsen/logrus" library.
Package logrus is a wrapper of the original "github.com/sirupsen/logrus" library.
Package nolog is just a mock of logging which do nothing.
Package nolog is just a mock of logging which do nothing.
Package zap is a wrapper of the original "github.com/uber-go/zap" library.
Package zap is a wrapper of the original "github.com/uber-go/zap" library.
Package zerolog is a wrapper of the original "github.com/rs/zerolog" library.
Package zerolog is a wrapper of the original "github.com/rs/zerolog" library.

Jump to

Keyboard shortcuts

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