Skip to content

Commit 2045af8

Browse files
committed
docs: update readme
1 parent 5966486 commit 2045af8

File tree

1 file changed

+5
-36
lines changed

1 file changed

+5
-36
lines changed

README.md

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ package main
1515

1616
import (
1717
"fmt"
18-
"io"
1918
"net/http"
20-
"os"
2119
"regexp"
2220
"time"
2321

@@ -31,18 +29,6 @@ import (
3129
var rxURL = regexp.MustCompile(`^/regexp\d*`)
3230

3331
func main() {
34-
zerolog.SetGlobalLevel(zerolog.InfoLevel)
35-
if gin.IsDebugging() {
36-
zerolog.SetGlobalLevel(zerolog.DebugLevel)
37-
}
38-
39-
log.Logger = log.Output(
40-
zerolog.ConsoleWriter{
41-
Out: os.Stderr,
42-
NoColor: false,
43-
},
44-
)
45-
4632
r := gin.New()
4733

4834
// Add a logger middleware, which:
@@ -60,13 +46,6 @@ func main() {
6046
logger.WithSkipPath([]string{"/skip"}),
6147
logger.WithUTC(true),
6248
logger.WithSkipPathRegexp(rxURL),
63-
logger.WithLogger(func(c *gin.Context, out io.Writer, latency time.Duration) zerolog.Logger {
64-
return zerolog.New(out).With().
65-
Str("foo", "bar").
66-
Str("path", c.Request.URL.Path).
67-
Dur("latency", latency).
68-
Logger()
69-
}),
7049
), func(c *gin.Context) {
7150
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
7251
})
@@ -92,24 +71,14 @@ func main() {
9271
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
9372
})
9473

95-
// Example custom log level.
96-
r.GET("/debugonly", logger.SetLogger(
97-
logger.WithDefaultLevel(zerolog.DebugLevel),
98-
), func(c *gin.Context) {
99-
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
100-
})
101-
102-
r.GET("/id", requestid.New(requestid.Config{
103-
Generator: func() string {
104-
return "foo-bar"
105-
},
106-
}), logger.SetLogger(
107-
logger.WithLogger(func(c *gin.Context, out io.Writer, latency time.Duration) zerolog.Logger {
108-
return zerolog.New(out).With().
74+
r.GET("/id", requestid.New(requestid.WithGenerator(func() string {
75+
return "foobar"
76+
})), logger.SetLogger(
77+
logger.WithLogger(func(c *gin.Context, l zerolog.Logger) zerolog.Logger {
78+
return l.With().
10979
Str("id", requestid.Get(c)).
11080
Str("foo", "bar").
11181
Str("path", c.Request.URL.Path).
112-
Dur("latency", latency).
11382
Logger()
11483
}),
11584
), func(c *gin.Context) {

0 commit comments

Comments
 (0)