An open API service indexing awesome lists of open source software.

https://github.com/aubss/fasthttplogger

HTTP request logger middleware for FastHttp
https://github.com/aubss/fasthttplogger

fasthttp fasthttprouter go golang logger logger-middleware

Last synced: 2 months ago
JSON representation

HTTP request logger middleware for FastHttp

Awesome Lists containing this project

README

          

# FastHttpLogger
HTTP request logger middleware for FastHttp

##### Tiny / TinyColored
```
- -
GET /hello - 200 - 11.925 us
```

#### Short / ShortColored
```
| | - -
127.0.0.1:53324 | HTTP/1.1 | GET /hello - 200 - 44.8µs
```

#### Combined / CombinedColored
```
[

## Examples

### FastHttp
```go
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
```go
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"))
}
```