Documentation ¶
Overview ¶
Package echozap implements an echo.Logger interface as well as an echo Middleware to log requests.
Index ¶
- Variables
- func Middleware(logger *zap.Logger, options ...MiddlewareOption) echo.MiddlewareFunc
- func MiddlewareWithConfig(config MiddlewareConfig) echo.MiddlewareFunc
- type MiddlewareConfig
- type MiddlewareOption
- type ZapLogger
- func (l *ZapLogger) Debug(i ...interface{})
- func (l *ZapLogger) Debugf(format string, args ...interface{})
- func (l *ZapLogger) Debugj(j log.JSON)
- func (l *ZapLogger) Error(i ...interface{})
- func (l *ZapLogger) Errorf(format string, args ...interface{})
- func (l *ZapLogger) Errorj(j log.JSON)
- func (l *ZapLogger) Fatal(i ...interface{})
- func (l *ZapLogger) Fatalf(format string, args ...interface{})
- func (l *ZapLogger) Fatalj(j log.JSON)
- func (l *ZapLogger) Info(i ...interface{})
- func (l *ZapLogger) Infof(format string, args ...interface{})
- func (l *ZapLogger) Infoj(j log.JSON)
- func (l *ZapLogger) Level() log.Lvl
- func (l *ZapLogger) Middleware(options ...MiddlewareOption) echo.MiddlewareFunc
- func (l *ZapLogger) Output() io.Writer
- func (l *ZapLogger) Panic(i ...interface{})
- func (l *ZapLogger) Panicf(format string, args ...interface{})
- func (l *ZapLogger) Panicj(j log.JSON)
- func (l *ZapLogger) Prefix() string
- func (l *ZapLogger) Print(i ...interface{})
- func (l *ZapLogger) Printf(format string, args ...interface{})
- func (l *ZapLogger) Printj(j log.JSON)
- func (l *ZapLogger) SetHeader(_ string)
- func (l *ZapLogger) SetLevel(_ log.Lvl)
- func (l *ZapLogger) SetOutput(_ io.Writer)
- func (l *ZapLogger) SetPrefix(p string)
- func (l *ZapLogger) Warn(i ...interface{})
- func (l *ZapLogger) Warnf(format string, args ...interface{})
- func (l *ZapLogger) Warnj(j log.JSON)
Constants ¶
This section is empty.
Variables ¶
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 (*ZapLogger) Debug ¶
func (l *ZapLogger) Debug(i ...interface{})
Debug implements echo's Logger interface.
func (*ZapLogger) Error ¶
func (l *ZapLogger) Error(i ...interface{})
Error implements echo's Logger interface.
func (*ZapLogger) Fatal ¶
func (l *ZapLogger) Fatal(i ...interface{})
Fatal implements echo's Logger interface.
func (*ZapLogger) Info ¶
func (l *ZapLogger) Info(i ...interface{})
Info implements echo's Logger interface.
func (*ZapLogger) Middleware ¶
func (l *ZapLogger) Middleware(options ...MiddlewareOption) echo.MiddlewareFunc
Middleware returns a new echo middleware with the provided logger.
func (*ZapLogger) Output ¶
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) Prefix ¶
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) SetLevel ¶
SetLevel does nothing as zap doesn't expose a way to change the level for a logger.
func (*ZapLogger) SetOutput ¶
SetOutput does nothing, as zaps underlying writer is unable to be changed.
func (*ZapLogger) Warn ¶
func (l *ZapLogger) Warn(i ...interface{})
Warn implements echo's Logger interface.