lax

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: BSD-2-Clause-Patent Imports: 8 Imported by: 7

README

lax

Build Status Go Reference Go Report License

Logger abstraction in Go.

Besides implementing own logger interface, all adapters also implement pgx.Logger interface and may implement more interfaces in the future. This eliminates usage of multiple adapters.

Adapters

Contribution

  • make lint lints the project
  • make test runs unit tests
  • make test-cov displays test coverage (requires docker-stack to be up)

Documentation

Overview

Package lax contains logger abstraction and adapters for the most common loggers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(log Logger) func(next http.Handler) http.Handler

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

func NewZapLogger(format, level string, callerSkip int) (*zap.Logger, error)

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.

func Any

func Any(key string, value interface{}) Field

Any creates field with an attribute value of any type.

func Duration

func Duration(key string, value time.Duration) Field

Duration creates field with an attribute of time.Duration type.

func Error

func Error(value error) Field

Error creates field with an attribute of error type.

func Int

func Int(key string, value int) Field

Int creates field with an attribute of int type.

func String

func String(key string, value string) Field

String creates field with an attribute of string type.

func Time

func Time(key string, value time.Time) Field

Time creates field with an attribute of time.Time type.

func Uint

func Uint(key string, value uint) Field

Uint creates field with an attribute of uint type.

func Uint64

func Uint64(key string, value uint64) Field

Uint64 creates field with an attribute of uint64 type.

func Uint8

func Uint8(key string, value uint8) Field

Uint8 creates field with an attribute of uint8 type.

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.

Jump to

Keyboard shortcuts

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