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
- Host: GitHub
- URL: https://github.com/aubss/fasthttplogger
- Owner: AubSs
- License: mit
- Created: 2017-05-31T11:40:01.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-31T12:32:29.000Z (about 9 years ago)
- Last Synced: 2025-12-18T02:27:06.343Z (6 months ago)
- Topics: fasthttp, fasthttprouter, go, golang, logger, logger-middleware
- Language: Go
- Size: 4.88 KB
- Stars: 7
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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"))
}
```