Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.
/ goji-logger Public archive

NOTE: This is a test release. Expect it to change to `goji/logger` soon! Package goji/logger provides request logging and request ID generation for Goji (https://goji.io/), a HTTP multiplexer written in Go.

License

Notifications You must be signed in to change notification settings

elithrar/goji-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goji/logger

goji/logger provides request logging and ID generation middleware for Goji, a HTTP multiplexer written in Go.

The middleware functions include:

  • Logger - a request logger that logs the method, remote IP and execution time of the request to stdout. When outputting to a terminal, the output is colorized for readability.
  • RequestID generates a random base62 identifier for the request. When used before the Logger middleware, the RequestID is included in the log output.

Here's what it looks like:

Install It

$ go get github.com/goji/logger

Example

Here's an example of the logger.RequestID and logger.Logger middleware in action:

package main

import (
	"fmt"
	"log"
	"net/http"

	"golang.org/x/net/context"

	"github.com/goji/logger"
	"goji.io"
	"goji.io/pat"
)

func main() {
	mux := goji.NewMux()
    // Include logger.RequestID before logger.Logger, and the request ID will
    // automatically be added to the log output.
	mux.UseC(logger.RequestID)
	mux.UseC(logger.Logger)

	mux.HandleFuncC(pat.Get("/"), SomeHandler)

	log.Fatal(http.ListenAndServe("localhost:8000", mux))
}

func SomeHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, "Goji!\n")
}

Note: Provided you implement the goji.Handler interface in your own application, this middleware can be used beyond just Goji.

License

MIT licensed. See the LICENSE file for details.

About

NOTE: This is a test release. Expect it to change to `goji/logger` soon! Package goji/logger provides request logging and request ID generation for Goji (https://goji.io/), a HTTP multiplexer written in Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages