Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
/ fasthttplogger Public archive
forked from AubSs/fasthttplogger

HTTP request logger middleware for FastHttp

License

Notifications You must be signed in to change notification settings

pablodz/fasthttplogger

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastHttpLogger

HTTP request logger middleware for FastHttp

Install

go get -v github.com/pablodz/fasthttplogger/fasthttplogger
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"))
}

About

HTTP request logger middleware for FastHttp

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%