Documentation
¶
Overview ¶
package logx is a package for logging with echo and
Index ¶
- func Ctx(ctx context.Context) *zerolog.Logger
- func LoggingMiddleware(config Config) echo.MiddlewareFunc
- func MatchEchoLevel(level log.Lvl) (zerolog.Level, log.Lvl)
- func MatchZeroLevel(level zerolog.Level) (log.Lvl, zerolog.Level)
- type Config
- type ConfigSetter
- func WithCaller() ConfigSetter
- func WithCallerWithSkipFrameCount(skipFrameCount int) ConfigSetter
- func WithField(name string, value any) ConfigSetter
- func WithFields(fields map[string]any) ConfigSetter
- func WithHook(hook zerolog.Hook) ConfigSetter
- func WithHookFunc(hook zerolog.HookFunc) ConfigSetter
- func WithLevel(level log.Lvl) ConfigSetter
- func WithPrefix(prefix string) ConfigSetter
- func WithTimestamp() ConfigSetter
- type Context
- type Enricher
- type Logger
- func (l *Logger) Debug(i ...any)
- func (l *Logger) Debugf(format string, i ...any)
- func (l *Logger) Debugj(j log.JSON)
- func (l *Logger) Error(err error)
- func (l *Logger) Errorf(format string, i ...any)
- func (l *Logger) Errorj(j log.JSON)
- func (l *Logger) Fatal(i ...any)
- func (l *Logger) Fatalf(format string, i ...any)
- func (l *Logger) Fatalj(j log.JSON)
- func (l *Logger) Info(i ...any)
- func (l *Logger) Infof(format string, i ...any)
- func (l *Logger) Infoj(j log.JSON)
- func (l *Logger) Level() log.Lvl
- func (l *Logger) Output() io.Writer
- func (l *Logger) Panic(i ...any)
- func (l *Logger) Panicf(format string, i ...any)
- func (l *Logger) Panicj(j log.JSON)
- func (l *Logger) Prefix() string
- func (l *Logger) Print(i ...any)
- func (l *Logger) Printf(format string, i ...any)
- func (l *Logger) Printj(j log.JSON)
- func (l *Logger) SetHeader(_ string)
- func (l *Logger) SetLevel(level log.Lvl)
- func (l *Logger) SetOutput(newOut io.Writer)
- func (l *Logger) SetPrefix(newPrefix string)
- func (l *Logger) Unwrap() zerolog.Logger
- func (l *Logger) Warn(i ...any)
- func (l *Logger) Warnf(format string, i ...any)
- func (l *Logger) Warnj(j log.JSON)
- func (l Logger) WithContext(ctx context.Context) context.Context
- func (l *Logger) Write(p []byte) (n int, err error)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ctx ¶
Ctx returns a logger from the provided context; if no logger is found in the context, a new one is created
func LoggingMiddleware ¶
func LoggingMiddleware(config Config) echo.MiddlewareFunc
LoggingMiddleware is a middleware that logs requests using the provided logger
func MatchEchoLevel ¶
MatchEchoLevel returns a zerolog level and echo level for a given echo level
Types ¶
type Config ¶
type Config struct {
// Logger is a custom instance of the logger to use
Logger *Logger
// Skipper defines a function to skip middleware
Skipper middleware.Skipper
// AfterNextSkipper defines a function to skip middleware after the next handler is called
AfterNextSkipper middleware.Skipper
// BeforeNext is a function that is executed before the next handler is called
BeforeNext middleware.BeforeFunc
// Enricher is a function that can be used to enrich the logger with additional information
Enricher Enricher
// RequestIDHeader is the header name to use for the request ID in a log record
RequestIDHeader string
// RequestIDKey is the key name to use for the request ID in a log record
RequestIDKey string
// NestKey is the key name to use for the nested logger in a log record
NestKey string
// HandleError indicates whether to propagate errors up the middleware chain, so the global error handler can decide appropriate status code
HandleError bool
// For long-running requests that take longer than this limit, log at a different level
RequestLatencyLimit time.Duration
// The level to log at if RequestLatencyLimit is exceeded
RequestLatencyLevel zerolog.Level
}
Config defines the config for the echolog middleware
type ConfigSetter ¶
type ConfigSetter func(opts *Options)
ConfigSetter is a function that sets an option on a Logger
func WithCallerWithSkipFrameCount ¶
func WithCallerWithSkipFrameCount(skipFrameCount int) ConfigSetter
WithCallerWithSkipFrameCount sets the caller with a skip frame count on a Logger
func WithField ¶
func WithField(name string, value any) ConfigSetter
WithField sets a field on a Logger
func WithFields ¶
func WithFields(fields map[string]any) ConfigSetter
WithFields sets fields on a Logger
func WithHookFunc ¶
func WithHookFunc(hook zerolog.HookFunc) ConfigSetter
WithHookFunc sets the hook function on a Logger
func WithPrefix ¶
func WithPrefix(prefix string) ConfigSetter
WithPrefix sets the prefix on a Logger
type Context ¶
Context is a wrapper around echo.Context that provides a logger
func NewContext ¶
NewContext returns a new Context
type Enricher ¶
Enricher is a function that can be used to enrich the logger with additional information
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a wrapper around zerolog.Logger that provides an implementation of the echo.Logger interface
func From ¶
func From(log zerolog.Logger, setters ...ConfigSetter) *Logger
From returns a new Logger instance using existing zerolog log
func New ¶
func New(out io.Writer, setters ...ConfigSetter) *Logger
New returns a new Logger instance
func (Logger) WithContext ¶
WithContext returns a new context with the provided logger
Directories
¶
| Path | Synopsis |
|---|---|
|
Package console log is a zerolog consolewriter output formatter that can be used generically with any zerolog instantiation so that it's not specific to a particular application
|
Package console log is a zerolog consolewriter output formatter that can be used generically with any zerolog instantiation so that it's not specific to a particular application |