2016-09-26 14:53:39 +03:00
|
|
|
# gin-logrus
|
2016-09-26 17:22:16 +03:00
|
|
|
|
|
|
|
[Logrus](https://github.com/Sirupsen/logrus) logger middleware for [Gin](https://gin-gonic.github.io/gin/)
|
|
|
|
|
|
|
|
![golang gin middleware logrus logger](http://i.imgur.com/P140Vi0.png)
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
```go
|
|
|
|
import (
|
2022-12-12 14:35:16 +03:00
|
|
|
"git.internal/re/logrus"
|
|
|
|
"git.internal/re/gin-logrus"
|
2016-09-26 17:22:16 +03:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
log := logrus.New()
|
2016-09-26 17:24:27 +03:00
|
|
|
// hooks, config,...
|
|
|
|
|
2016-09-26 17:22:16 +03:00
|
|
|
r := gin.New()
|
|
|
|
r.Use(ginlogrus.Logger(log), gin.Recovery())
|
|
|
|
|
|
|
|
// pingpong
|
|
|
|
r.GET("/ping", func(c *gin.Context) {
|
|
|
|
c.Data(200, "text/plain", []byte("pong"))
|
|
|
|
})
|
|
|
|
|
|
|
|
r.Run("127.0.0.1:8080")
|
2021-02-18 18:09:50 +03:00
|
|
|
```
|