echozap

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: MIT Imports: 6 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/dhillondeep/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

View Source
const (
	// DefaultCustomFieldsKey is the key for custom fields in the context.
	DefaultCustomFieldsKey = "_echozap_custom_fields_"
	// DefaultCustomLoggerKey is the key for custom logger in the context.
	DefaultCustomLoggerKey = "_echozap_custom_logger_"
)

Variables

This section is empty.

Functions

func ZapLogger

func ZapLogger(options *Options) echo.MiddlewareFunc

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

Types

type Options

type Options struct {
	// Logger is the zap logger to use
	Logger *zap.Logger
	// CustomFieldsKey is the key to use for custom fields (default: echozap.DefaultCustomFieldsPrefix)
	CustomFieldsKey string
	// CustomLoggerKey is the key to use for the custom logger (default: echozap.DefaultCustomLoggerKey)
	CustomLoggerKey string
}

Jump to

Keyboard shortcuts

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