echozap

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

echozap - Public Fork

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

Echo version: This is the v2 line of the fork, which targets Echo v5. The module path is github.com/Unity-Technologies/echozap/v2, so import it with the /v2 suffix. For Echo v4, use a v1.x release of the fork.

Usage

package main

import (
	"log"
	"net/http"

	"github.com/Unity-Technologies/echozap/v2"
	"github.com/labstack/echo/v5"
	"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!")
	})

	if err := e.Start(":1323"); err != nil {
		log.Fatal(err)
	}
}

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 (
	// DefaultZapLoggerConfig is the default ZapLogger middleware config.
	DefaultZapLoggerConfig = ZapLoggerConfig{
		Skipper:                  DefaultSkipper,
		IncludeRequestLogMessage: false,
	}
)

Functions

func DefaultSkipper

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

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

ZapLoggerWithConfig is a middleware (with configuration) and zap to provide an "access log" like logging for each request.

Types

type Skipper

type Skipper func(c *echo.Context) bool

type ZapLoggerConfig

type ZapLoggerConfig struct {
	// Skipper defines a function to skip middleware
	Skipper Skipper
	// Whether to include the request method and URI in the log message field
	// Makes it easier to visualize the logs in systems that expand only the log message by default(e.g. Stackdriver)
	IncludeRequestLogMessage bool
}

ZapLoggerConfig defines the config for ZapLogger middleware

Jump to

Keyboard shortcuts

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