httplog

package module
v0.0.0-...-8dddff4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 6 Imported by: 1

README

httplog middleware

Go Report Card Build Status

negroni middleware

Install

go get -u github.com/syhlion/httplog

Example

package main

import (
  "fmt"
  "net/http"

  "github.com/urfave/negroni"
)

func main() {
  mux := http.NewServeMux()
  mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
    fmt.Fprintf(w, "Welcome to the home page!")
  })

  n := negroni.New()
  n.Use(httplog.NewLogger())
  n.UseHandler(mux)

  http.ListenAndServe(":3004", n)
}

Will print a log similar to:


[http log] 127.0.0.1:46945 - [2015-12-30 09:05:27.502464588 +0800 CST] "POST /register" 200 37.96608ms  "username=syhlion&email=xxx@gmail.com"
[http log] 127.0.0.1:46947 - [2015-12-30 10:06:29.502464588 +0800 CST] "GET /feeds" 200 37.96608ms  ""
[http log] 127.0.0.1:46956 - [2015-12-31 12:15:33.502464588 +0800 CST] "GET /news" 200 37.96608ms  "offset=0&limit=10"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// Logger inherits from log.Logger used to log messages with the Logger middleware
	*log.Logger
	// contains filtered or unexported fields
}

Logger is a middleware handler that logs the request as it goes in and the response as it goes out.

func NewLogger

func NewLogger(jsonOut bool) *Logger

NewLogger returns a new Logger instance

func (*Logger) ServeHTTP

func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ServerHTTP negroni middleware interface

Jump to

Keyboard shortcuts

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