echozap

package module
v1.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 9 Imported by: 0

README

echozap

Middleware for Golang Echo framework that provides integration with Uber´s Zap logging library for logging HTTP requests.

Commitizen friendly semantic-release

Actions Status Codacy Badge Codacy Badge

Pre-requisites

Usage

package main

import (
	"net/http"

	"github.com/brpaz/echozap"
	"github.com/labstack/echo/v4"
	"go.uber.org/zap"
)

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

	zapLogger, _ := zap.NewProduction()

	e.Use(echozap.ZapLogger(zapLogger))

	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, World!")
	})
	e.Logger.Fatal(e.Start(":1323"))
}

Logged details

The following information is logged:

  • Status Code
  • Time
  • Uri
  • Method
  • Hostname
  • Remote IP Address

Todo

  • Add more customization options.

🤝 Contributing

Contributions, issues and feature requests are welcome!

Show your support

If this project have been useful for you, I would be grateful to have your support.

Give a ⭐️ to the project, or just:

Buy Me A Coffee

Author

👤 Bruno Paz

📝 License

Copyright © 2019 Bruno Paz.

This project is MIT licensed.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Skipper:     DefaultSkipper,
	ContextKeys: nil,
	PrintBody:   true,
	LogLevel:    DefaultLogLevel,
}

Functions

func DefaultLogLevel added in v1.1.11

func DefaultLogLevel(status int) zapcore.Level

DefaultLogLevel is Error for HTTP 5xx, Warn for 4xx, and Info otherwise.

func DefaultSkipper added in v1.1.4

func DefaultSkipper(echo.Context) bool

DefaultSkipper returns false which processes the middleware.

func ZapLogger

func ZapLogger(log *zap.Logger) echo.MiddlewareFunc

ZapLogger is a middleware and zap to provide an "access log" like logging for each request.

func ZapLoggerWithConfig added in v1.1.4

func ZapLoggerWithConfig(log *zap.Logger, config Config) echo.MiddlewareFunc

Types

type Config added in v1.1.4

type Config struct {
	// Skipper defines a function to skip middleware.
	Skipper Skipper

	// ContextKeys defines the keys which should be added to the logger, as fields, from the context.
	ContextKeys []interface{}

	// PrintBody defines if the body of the request should be printed, if it exists.
	PrintBody bool

	// LogLevel selects the log level to use depending on HTTP status.
	LogLevel func(status int) zapcore.Level
}

type Skipper added in v1.1.4

type Skipper func(echo.Context) bool

Jump to

Keyboard shortcuts

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