Skip to content
This repository was archived by the owner on May 19, 2020. It is now read-only.

Commit 42f9c4f

Browse files
committed
usage in readme
1 parent 112f01f commit 42f9c4f

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,56 @@
11
logs-go-gin
22
-----------
33

4-
Logger fo gin gonic
4+
Logger fo gin gonic
5+
6+
## Usage
7+
8+
Initiate new [logger](https://github.com/microparts/logs-go) with prefilled `logs.Config` and use it to initiate new gin logger
9+
10+
```go
11+
package main
12+
13+
import (
14+
"time"
15+
16+
"github.com/gin-gonic/gin"
17+
"github.com/microparts/logs-go"
18+
"github.com/microparts/logs-go-gin"
19+
)
20+
21+
func main() {
22+
// initiate logs-go
23+
conf := &logs.Config{
24+
Level:"warn",
25+
Format: "text",
26+
Sentry: &logs.SentryConfig{
27+
Enable: true,
28+
Stage:"test",
29+
DSN: "http://dsn.sentry.com",
30+
ResponseTimeout: 0,
31+
StackTrace: logs.StackTraceConfig{
32+
Enable: true,
33+
},
34+
},
35+
}
36+
37+
l, err := logs.NewLogger(conf)
38+
if err != nil {
39+
panic(err)
40+
}
41+
42+
r := gin.New()
43+
r.Use(ginLogger.NewLogger(l), gin.Recovery())
44+
45+
// pingpong
46+
r.GET("/ping", func(c *gin.Context) {
47+
c.Data(200, "text/plain", []byte("pong"))
48+
})
49+
50+
_ = r.Run("127.0.0.1:8080")
51+
}
52+
```
53+
54+
## Licence
55+
56+
The software is provided under [MIT Licence](LICENCE).

logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/sirupsen/logrus"
99
)
1010

11-
// MuxLogger logs gin gonic actions
12-
func GinLogger(l *logrus.Logger) gin.HandlerFunc {
11+
// NewLogger logs gin gonic actions
12+
func NewLogger(l *logrus.Logger) gin.HandlerFunc {
1313
hostname, err := os.Hostname()
1414
if err != nil {
1515
hostname = "unknown"

0 commit comments

Comments
 (0)