log

package
v0.13.9 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: MIT Imports: 23 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 Config added in v0.9.0

type Config struct {
	Type       LogType
	Level      LogLevel
	JsonFormat bool
	Color      bool

	// For elasticsearch.
	ElasticsearchAddresses []string
	ElasticsearchUser      string
	ElasticsearchPassword  string
	ElasticsearchIndex     string
	ElasticsearchIsSync    bool
}

Config is log config.

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
	Elasticsearch
)

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(cfg Config) (Logger, error)

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

func NewChain added in v0.10.0

func NewChain(logger Logger, loggers ...Logger) Logger

NewChain to create new logger chain. Useful if you want to print the log in local and send the log to third party at the same time.

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
	// Show raw path (includes query params).
	RawPath 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 elasticsearch is a wrapper of the original "github.com/elastic/go-elasticsearch".
Package elasticsearch is a wrapper of the original "github.com/elastic/go-elasticsearch".
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