Documentation
¶
Overview ¶
Package lax contains logger abstraction and adapters for the most common loggers.
Index ¶
- func Middleware(log Logger) func(next http.Handler) http.Handler
- func NewZapLogger(format, level string, callerSkip int) (*zap.Logger, error)
- type Field
- func Any(key string, value interface{}) Field
- func Duration(key string, value time.Duration) Field
- func Error(value error) Field
- func Int(key string, value int) Field
- func String(key string, value string) Field
- func Time(key string, value time.Time) Field
- func Uint(key string, value uint) Field
- func Uint64(key string, value uint64) Field
- func Uint8(key string, value uint8) Field
- type Logger
- type ZapAdapter
- func (l *ZapAdapter) Debug(message string, fields ...Field)
- func (l *ZapAdapter) Error(message string, fields ...Field)
- func (l *ZapAdapter) Flush()
- func (l *ZapAdapter) Info(message string, fields ...Field)
- func (l *ZapAdapter) Log(ctx context.Context, level pgx.LogLevel, msg string, ...)
- func (l *ZapAdapter) Warn(message string, fields ...Field)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
Middleware is Go idiomatic middleware which logs request statistic data using lax logger. Additionally, If Chi's middleware.RequestID is used before this middleware, request id will be logged.
func NewZapLogger ¶
NewZapLogger creates zap logger using ectobit.com proposed configuration.
format may be either console or json. level may be one of debug, info, warn or error. For level debug and format console output will be colored. callerSkip defines how many callers should be skipped when logging. Useful when zap logger is wrapped.
Logger will show stack trace just in error case.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is a general type to log typed values as log message attributes.
type Logger ¶
type Logger interface { // Debug sends a message to logger at debug level. Debug(string, ...Field) // Info sends a message to logger at info level. Info(string, ...Field) // Warn sends a message to logger at warn level. Warn(string, ...Field) // Error sends a message to logger at error level. Error(string, ...Field) // Flush flushes buffer ignoring eventual error. Flush() }
Logger is an abstraction of typical logger methods.
type ZapAdapter ¶
type ZapAdapter struct {
// contains filtered or unexported fields
}
ZapAdapter implements Logger and pgx.Logger interfaces for zap logger.
func NewDefaultZapAdapter ¶
func NewDefaultZapAdapter(format, level string) (*ZapAdapter, error)
NewDefaultZapAdapter creates zap logger adapter using ectobit.com proposed configuration.
format may be either console or json. level may be one of debug, info, warn or error. For level debug and format console output will be colored.
Logger will show stack trace just in error case.
func NewZapAdapter ¶
func NewZapAdapter(l *zap.Logger) *ZapAdapter
NewZapAdapter creates zap logger adapter.
func (*ZapAdapter) Debug ¶
func (l *ZapAdapter) Debug(message string, fields ...Field)
Debug sends a message to logger at debug level.
func (*ZapAdapter) Error ¶
func (l *ZapAdapter) Error(message string, fields ...Field)
Error sends a message to logger at error level.
func (*ZapAdapter) Flush ¶
func (l *ZapAdapter) Flush()
Flush flushes buffer ignoring eventual error.
func (*ZapAdapter) Info ¶
func (l *ZapAdapter) Info(message string, fields ...Field)
Info sends a message to logger at info level.
func (*ZapAdapter) Log ¶
func (l *ZapAdapter) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{})
Log is the interface used to get logging from pgx internals.
func (*ZapAdapter) Warn ¶
func (l *ZapAdapter) Warn(message string, fields ...Field)
Warn sends a message to logger at warn level.