logger

package module
v0.0.0-...-e381e9e Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 License: MIT Imports: 4 Imported by: 8

README

logger GoDoc Go Report Card

Simple go-chi logging middleware for zap

Installation

go get github.com/treastech/logger

Usage

package main

import (
	l "github.com/treastech/logger"
	"github.com/go-chi/chi"
	"go.uber.org/zap"
	"net/http"
)

func main() {

	logger, _ := zap.NewProduction()
	defer logger.Sync() // flushes buffer, if any

	r := chi.NewRouter()

	// instead of
	// r.Use(middleware.Logger)
	// use
	r.Use(l.Logger(logger))
	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("welcome"))
	})
	http.ListenAndServe(":3000", r)
}

Sample log output

{"level":"info","ts":1530826215.6541932, "msg":"Served","proto":"HTTP/1.1","path":"/","lat":0.032019407,"status":200,"size":7,"reqId":"localhost/FsNkQGYAQA-000036"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(l *zap.Logger) func(next http.Handler) http.Handler

Logger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return.

Types

This section is empty.

Jump to

Keyboard shortcuts

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