Documentation
¶
Overview ¶
Package logx is a package for logging with echo and
Index ¶
- func Ctx(ctx context.Context) *zerolog.Logger
- func FromContext(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)
- func SeedContext(ctx context.Context) context.Context
- type Config
- type 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 LoggerConfig
- type LoggerSet
- 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 FromContext ¶ added in v0.43.0
FromContext returns the logger stored on the context or falls back to the global logger.
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
func MatchZeroLevel ¶
MatchZeroLevel returns an echo level and zerolog level for a given zerolog 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
// AttachRequestMetadata controls whether stable request metadata (client origin IP, user agent, and forwarding headers)
// is attached to the request-scoped logger context so downstream log entries can include it.
AttachRequestMetadata bool
}
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 WithSeverityMapping ¶ added in v0.43.0
func WithSeverityMapping() ConfigSetter
WithSeverityMapping ensures each log event has a severity field aligned with GCP expectations
func WithZeroLevel ¶ added in v0.43.0
func WithZeroLevel(level zerolog.Level) ConfigSetter
WithZeroLevel sets the zerolog level on a Logger while keeping the echo level in sync
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 (Logger) WithContext ¶
WithContext returns a new context with the provided logger
type LoggerConfig ¶ added in v0.43.0
type LoggerConfig struct {
// Level sets the zerolog level. Use zerolog.NoLevel to keep the existing global default.
Level zerolog.Level
// Pretty toggles human-readable console output instead of structured JSON.
Pretty bool
// Writer controls where logs are written. Defaults to os.Stdout.
Writer io.Writer
// IncludeCaller attaches caller information to each log entry.
IncludeCaller bool
// Hooks are applied to every log event.
Hooks []zerolog.HookFunc
// WithEcho instructs Configure to build an echo-compatible logger.
WithEcho bool
// SetGlobal updates zerolog's global logger (`log.Logger`) using the configured settings.
SetGlobal bool
}
LoggerConfig controls how loggers produced by Configure behave.
Source Files
¶
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 |