eglm

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: MIT Imports: 6 Imported by: 0

README

eglm

echo log middleware library dedicated to gwlog.

Usage

Please add it to Middleware of echo.

Also, set gwlog.Logger for the Logger of the echo.

e := echo.New()
logger := gwlog.GetLogger()
logger.SetOutput(os.Stdout)
e.Logger = logger
e.Use(eglm.Middleware(&Config{}))

Options

Skipper

Log output is skip if the conditions are met in request.

The default is not to skip everything.

e := echo.New()
e.Logger = gwlog.GetLogger()
e.Use(eglm.Logger(&Config{
    Skipper: func(c echo.Context) bool {
        return c.Path() == "/"
    },
}))

LoggingFunc

Write the log via Middleware.

Use this when you want to customize the log contents.

If nothing is set, eglm.DefaultLoggingFunc will be set.

e := echo.New()
e.Logger = gwlog.GetLogger()
e.Use(eglm.Logger(&Config{
    LoggingFunc: func(logger gwlog.Logger, p *Parameter, c echo.Context) error {
    	logger.Print("a")
        return nil
    },
}))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLoggingFunc

func DefaultLoggingFunc(logger gwlog.Logger, param *Parameter, _ echo.Context) error

DefaultLoggingFunc is default write log function

func Middleware

func Middleware(config *Config) echo.MiddlewareFunc

Middleware echo write log middleware

Types

type Config

type Config struct {
	Skipper     em.Skipper
	LoggingFunc LoggingFunc
}

Config is Middleware config

type DefaultLogField

type DefaultLogField struct {
	Type         string `json:"type"`
	Status       int    `json:"status"`
	Method       string `json:"method"`
	Path         string `json:"path"`
	UserAgent    string `json:"userAgent"`
	RemoteIP     string `json:"remoteIp"`
	ForwardedFor string `json:"forwardedFor"`
	Latency      int    `json:"latency"`
	Error        string `json:"error"`
	RequestID    string `json:"requestId"`
}

DefaultLogField echo default log fields.

func (*DefaultLogField) ToJSON

func (d *DefaultLogField) ToJSON() ([]byte, error)

ToJSON struct attributes to json

func (*DefaultLogField) ToMap

func (d *DefaultLogField) ToMap() map[string]interface{}

ToMap struct attributes to map

type LoggingFunc

type LoggingFunc func(logger gwlog.Logger, param *Parameter, c echo.Context) error

LoggingFunc is write log function

type Parameter

type Parameter struct {
	ID        string
	Method    string
	Host      string
	URI       string
	Status    int
	Path      string
	RemoteIP  string
	Referer   string
	UserAgent string
	Latency   int
	BytesIn   string
	BytesOut  string
	Error     error
}

Parameter is LoggingFunc parameter struct

Jump to

Keyboard shortcuts

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