README

Logger for echo

Example

package main

import (
    "github.com/labstack/echo/v4"
    echolog "github.com/onrik/logrus/echo"
    "github.com/sirupsen/logrus"
)

func main() {
    server := echo.New()

    server.Logger = echolog.NewLogger(logrus.StandardLogger(), "")
    server.Use(echolog.Middleware(echolog.DefaultConfig))
}
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is the default Logger middleware config.
	DefaultConfig = Config{
		Logger:  logrus.StandardLogger(),
		Skipper: func(c echo.Context) bool { return false },
		Fields:  []string{"ip", "latency", "status"},
		Status:  0,
	}
)

Functions

func Middleware

func Middleware(config Config) echo.MiddlewareFunc

    Middleware returns a Logger middleware with config.

    Types

    type Config

    type Config struct {
    	Logger *logrus.Logger
    	// Skipper defines a function to skip middleware.
    	Skipper Skipper
    
    	// Fields available for logging
    	// - id (Request ID)
    	// - ip
    	// - host
    	// - referer
    	// - user_agent
    	// - status
    	// - latency
    	// - headers
    	Fields []string
    	Status int
    }

      Config defines the config for Logger middleware.

      type Logger

      type Logger struct {
      	*logrus.Logger
      
      	MsgField string
      	// contains filtered or unexported fields
      }

      func NewLogger

      func NewLogger(l *logrus.Logger, prefix string) *Logger

        NewLogger creates logger

        func (*Logger) Debugj

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

        func (*Logger) Errorj

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

        func (*Logger) Fatalj

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

        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) Panicj

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

        func (*Logger) Prefix

        func (l *Logger) Prefix() string

        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(lvl log.Lvl)

        func (*Logger) SetOutput

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

        func (*Logger) SetPrefix

        func (l *Logger) SetPrefix(prefix string)

        func (*Logger) Warnj

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

        type Skipper

        type Skipper func(c echo.Context) bool

          Skipper defines a function to skip middleware.