lecho

package module
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: MIT Imports: 10 Imported by: 0

README

lecho 🍅

Zerolog wrapper for Echo web framework.

Installation

For Echo v4:

go get github.com/ziflex/lecho/v2

For Echo v3:

go get github.com/ziflex/lecho

Quick start

e := echo.New()
e.Logger = lecho.New(os.Stdout)

Options


import (
	"os",
	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
	"github.com/ziflex/lecho/v2"
)

func main() {
    e := echo.New()
    e.Logger = lecho.New(
       os.Stdout,
       lecho.WithLevel(log.DEBUG),
       lecho.WithFields(map[string]interface{}{ "name": "lecho factory"}),
       lecho.WithTimestamp(),
       lecho.WithCaller(),
       lecho.WithPrefix("we ❤️ lecho"),
       lecho.WithHook(...),
       lecho.WithHookFunc(...),
    )
}

Middleware

Logging requests and attaching request id to a context logger

import (
	"os",
	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
	"github.com/ziflex/lecho/v2"
)

func main() {
    e := echo.New()
    logger := lecho.New(
            os.Stdout,
            lecho.WithLevel(log.DEBUG),
            lecho.WithTimestamp(),
            lecho.WithCaller(),
         )
    e.Logger = logger
    
    e.Use(middleware.RequestID())
    e.Use(lecho.Middleware(lecho.Config{
    	Logger: logger
    }))	
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(config Config) echo.MiddlewareFunc

Types

type Config

type Config struct {
	Logger  *Logger
	Skipper middleware.Skipper
}

type Context

type Context struct {
	echo.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx echo.Context, logger *Logger) *Context

func (*Context) Logger

func (c *Context) Logger() echo.Logger

type Logger

type Logger struct {
	echo.Logger
	// contains filtered or unexported fields
}

Logger is a wrapper around `zerolog.Logger` that provides an implementation of `echo.Logger` interface

func Ctx

func Ctx(ctx context.Context) *Logger

func New

func New(logger *zerolog.Logger, setters ...Setter) *Logger

New returns a new Logger instance

func (Logger) Clone

func (l Logger) Clone(setters ...Setter) *Logger

func (Logger) Debug

func (l Logger) Debug(i ...interface{})

func (Logger) Debugf

func (l Logger) Debugf(format string, i ...interface{})

func (Logger) Debugj

func (l Logger) Debugj(j log.JSON)

func (Logger) Error

func (l Logger) Error(i ...interface{})

func (Logger) Errorf

func (l Logger) Errorf(format string, i ...interface{})

func (Logger) Errorj

func (l Logger) Errorj(j log.JSON)

func (Logger) Fatal

func (l Logger) Fatal(i ...interface{})

func (Logger) Fatalf

func (l Logger) Fatalf(format string, i ...interface{})

func (Logger) Fatalj

func (l Logger) Fatalj(j log.JSON)

func (Logger) Info

func (l Logger) Info(i ...interface{})

func (Logger) Infof

func (l Logger) Infof(format string, i ...interface{})

func (Logger) Infoj

func (l Logger) Infoj(j log.JSON)

func (Logger) Level

func (l Logger) Level() log.Lvl

func (Logger) Output

func (l Logger) Output() io.Writer

func (Logger) Panic

func (l Logger) Panic(i ...interface{})

func (Logger) Panicf

func (l Logger) Panicf(format string, i ...interface{})

func (Logger) Panicj

func (l Logger) Panicj(j log.JSON)

func (Logger) Prefix

func (l Logger) Prefix() string

func (Logger) Print

func (l Logger) Print(i ...interface{})

func (Logger) Printf

func (l Logger) Printf(format string, i ...interface{})

func (Logger) Printj

func (l Logger) Printj(j log.JSON)

func (Logger) SetHeader

func (l Logger) SetHeader(h string)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level log.Lvl)

func (*Logger) SetOutput

func (l *Logger) SetOutput(newOut io.Writer)

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(newPrefix string)

func (Logger) Warn

func (l Logger) Warn(i ...interface{})

func (Logger) Warnf

func (l Logger) Warnf(format string, i ...interface{})

func (Logger) Warnj

func (l Logger) Warnj(j log.JSON)

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) context.Context

type Options

type Options struct {
	// contains filtered or unexported fields
}

type Setter

type Setter func(opts *Options)

func WithCaller

func WithCaller() Setter

func WithCallerWithSkipFrameCount

func WithCallerWithSkipFrameCount(skipFrameCount int) Setter

func WithField

func WithField(name string, value interface{}) Setter

func WithFields

func WithFields(fields map[string]interface{}) Setter

func WithHook

func WithHook(hook zerolog.Hook) Setter

func WithHookFunc

func WithHookFunc(hook zerolog.HookFunc) Setter

func WithLevel

func WithLevel(level log.Lvl) Setter

func WithPrefix

func WithPrefix(prefix string) Setter

func WithTimestamp

func WithTimestamp() Setter

Jump to

Keyboard shortcuts

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