fasthttplogger

package module
v0.0.0-...-7dab642 Latest Latest
Warning

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

Go to latest
Published: May 31, 2017 License: MIT Imports: 5 Imported by: 7

README

FastHttpLogger

HTTP request logger middleware for FastHttp

Tiny / TinyColored
<method> <url> - <status> - <response-time us>
GET /hello - 200 - 11.925 us
Short / ShortColored
<remote-addr> | <HTTP/:http-version> | <method> <url> - <status> - <response-time us>
127.0.0.1:53324 | HTTP/1.1 | GET /hello - 200 - 44.8µs
Combined / CombinedColored
[<time>] <remote-addr> | <HTTP/http-version> | <method> <url> - <status> - <response-time us> | <user-agent>
[2017/05/31 - 13:27:28] 127.0.0.1:54082 | HTTP/1.1 | GET /hello - 200 - 48.279µs | Paw/3.1.1 (Macintosh; OS X/10.12.5) GCDHTTPRequest

Examples

FastHttp
func Hello(ctx *fasthttp.RequestCtx) {
  fmt.Fprintf(ctx, "hello, %s!\n", ctx.UserValue("name"))
}

func main() {
	m := func(ctx *fasthttp.RequestCtx) {
		switch string(ctx.Path()) {
		case "/hello":
			Hello(ctx)
		default:
			ctx.Error("not found", fasthttp.StatusNotFound)
		}
	}

	fasthttp.ListenAndServe(":8080", fasthttplogger.Tiny(m))
}
FastHttp + FastHttpRouter
func Hello(ctx *fasthttp.RequestCtx) {
	fmt.Fprintf(ctx, "hello, %s!\n", ctx.UserValue("name"))
}

func main() {
	router := fasthttprouter.New()
	router.GET("/hello/:name", Hello)
	s := &fasthttp.Server{
		Handler: fasthttplogger.CombinedColored(router.Handler),
		Name: "FastHttpLogger",
	}
	log.Fatal(s.ListenAndServe(":8080"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Combined

Combined format: [<time>] <remote-addr> | <HTTP/http-version> | <method> <url> - <status> - <response-time us> | <user-agent> [2017/05/31 - 13:27:28] 127.0.0.1:54082 | HTTP/1.1 | GET /hello - 200 - 48.279µs | Paw/3.1.1 (Macintosh; OS X/10.12.5) GCDHTTPRequest

func CombinedColored

func CombinedColored(req fasthttp.RequestHandler) fasthttp.RequestHandler

CombinedColored is same as Combined but colored

func Short

Short format: <remote-addr> | <HTTP/:http-version> | <method> <url> - <status> - <response-time us> 127.0.0.1:53324 | HTTP/1.1 | GET /hello - 200 - 44.8µs

func ShortColored

ShortColored is same as Short but colored

func Tiny

Tiny format: <method> <url> - <status> - <response-time us> GET / - 200 - 11.925 us

func TinyColored

TinyColored is same as Tiny but colored

Types

This section is empty.

Jump to

Keyboard shortcuts

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