echozap

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Overview

Package echozap implements an echo.Logger interface as well as an echo Middleware to log requests.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLoggerRequired is returned when no logger was provided in the config.
	ErrLoggerRequired = errors.New("logger required")
)

Functions

func Middleware

func Middleware(logger *zap.Logger, options ...MiddlewareOption) echo.MiddlewareFunc

Middleware returns a new middleware using the provided logger.

func MiddlewareWithConfig

func MiddlewareWithConfig(config MiddlewareConfig) echo.MiddlewareFunc

MiddlewareWithConfig calls config.ToMiddleware returning the middleware if no error, if error is returned a panic is raised.

Types

type MiddlewareConfig

type MiddlewareConfig struct {
	// Logger defines the logger to write to.
	Logger *zap.Logger

	// Skipper defines a function to skip middleware.
	Skipper middleware.Skipper

	// CustomTimeFormat defines the time format the log should use.
	// Default time format is unix time.
	CustomTimeFormat string

	// ExtraFields defines additional fields to be added to the log.
	ExtraFields []zapcore.Field

	// ExtraFieldsHook allows for additional fields to be added dynamically.
	ExtraFieldsHook func(echo.Context) []zapcore.Field
}

MiddlewareConfig defines the config for Zap middleware.

func (MiddlewareConfig) ToMiddleware

func (config MiddlewareConfig) ToMiddleware() (echo.MiddlewareFunc, error)

ToMiddleware converts Config to middleware or returns an error for invalid configuration.

type MiddlewareOption

type MiddlewareOption func(c *MiddlewareConfig)

MiddlewareOption sets the middleware function definition.

func WithCustomTimeFormat

func WithCustomTimeFormat(format string) MiddlewareOption

WithCustomTimeFormat sets the middleware CustomTimeFormat config option.

func WithExtraFields

func WithExtraFields(fields []zapcore.Field) MiddlewareOption

WithExtraFields sets the middleware ExtraFields config option.

func WithExtraFieldsHook

func WithExtraFieldsHook(hook func(echo.Context) []zapcore.Field) MiddlewareOption

WithExtraFieldsHook sets the middleware ExtraFieldsHook config option.

func WithSkipper

func WithSkipper(skipper middleware.Skipper) MiddlewareOption

WithSkipper sets the middleware Skipper config option.

type ZapLogger

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

ZapLogger implements echo's Logger interface.

func NewLogger

func NewLogger(logger *zap.Logger) *ZapLogger

NewLogger creatse a new ZapLogger which implements echo.Logger.

func (*ZapLogger) Debug

func (l *ZapLogger) Debug(i ...interface{})

Debug implements echo's Logger interface.

func (*ZapLogger) Debugf

func (l *ZapLogger) Debugf(format string, args ...interface{})

Debugf implements echo's Logger interface.

func (*ZapLogger) Debugj

func (l *ZapLogger) Debugj(j log.JSON)

Debugj implements echo's Logger interface.

func (*ZapLogger) Error

func (l *ZapLogger) Error(i ...interface{})

Error implements echo's Logger interface.

func (*ZapLogger) Errorf

func (l *ZapLogger) Errorf(format string, args ...interface{})

Errorf implements echo's Logger interface.

func (*ZapLogger) Errorj

func (l *ZapLogger) Errorj(j log.JSON)

Errorj implements echo's Logger interface.

func (*ZapLogger) Fatal

func (l *ZapLogger) Fatal(i ...interface{})

Fatal implements echo's Logger interface.

func (*ZapLogger) Fatalf

func (l *ZapLogger) Fatalf(format string, args ...interface{})

Fatalf implements echo's Logger interface.

func (*ZapLogger) Fatalj

func (l *ZapLogger) Fatalj(j log.JSON)

Fatalj implements echo's Logger interface.

func (*ZapLogger) Info

func (l *ZapLogger) Info(i ...interface{})

Info implements echo's Logger interface.

func (*ZapLogger) Infof

func (l *ZapLogger) Infof(format string, args ...interface{})

Infof implements echo's Logger interface.

func (*ZapLogger) Infoj

func (l *ZapLogger) Infoj(j log.JSON)

Infoj implements echo's Logger interface.

func (*ZapLogger) Level

func (l *ZapLogger) Level() log.Lvl

Level returns an equivalent echo log level.

func (*ZapLogger) Middleware

func (l *ZapLogger) Middleware(options ...MiddlewareOption) echo.MiddlewareFunc

Middleware returns a new echo middleware with the provided logger.

func (*ZapLogger) Output

func (l *ZapLogger) Output() io.Writer

Output statically returns os.Stderr as zap doesn't expose the underlying writer.

func (*ZapLogger) Panic

func (l *ZapLogger) Panic(i ...interface{})

Panic implements echo's Logger interface.

func (*ZapLogger) Panicf

func (l *ZapLogger) Panicf(format string, args ...interface{})

Panicf implements echo's Logger interface.

func (*ZapLogger) Panicj

func (l *ZapLogger) Panicj(j log.JSON)

Panicj implements echo's Logger interface.

func (*ZapLogger) Prefix

func (l *ZapLogger) Prefix() string

Prefix returns an empty string as zap doesn't expose the underlying named logger.

func (*ZapLogger) Print

func (l *ZapLogger) Print(i ...interface{})

Print implements echo's Logger interface.

func (*ZapLogger) Printf

func (l *ZapLogger) Printf(format string, args ...interface{})

Printf implements echo's Logger interface.

func (*ZapLogger) Printj

func (l *ZapLogger) Printj(j log.JSON)

Printj implements echo's Logger interface.

func (*ZapLogger) SetHeader

func (l *ZapLogger) SetHeader(_ string)

SetHeader does nothing.

func (*ZapLogger) SetLevel

func (l *ZapLogger) SetLevel(_ log.Lvl)

SetLevel does nothing as zap doesn't expose a way to change the level for a logger.

func (*ZapLogger) SetOutput

func (l *ZapLogger) SetOutput(_ io.Writer)

SetOutput does nothing, as zaps underlying writer is unable to be changed.

func (*ZapLogger) SetPrefix

func (l *ZapLogger) SetPrefix(p string)

SetPrefix updates named logger with the provided prefix.

func (*ZapLogger) Warn

func (l *ZapLogger) Warn(i ...interface{})

Warn implements echo's Logger interface.

func (*ZapLogger) Warnf

func (l *ZapLogger) Warnf(format string, args ...interface{})

Warnf implements echo's Logger interface.

func (*ZapLogger) Warnj

func (l *ZapLogger) Warnj(j log.JSON)

Warnj implements echo's Logger interface.

Jump to

Keyboard shortcuts

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