Skip to content

treastech/logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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"}

Releases

No releases published

Packages

No packages published

Languages