Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewGlogrus ¶
NewGlogrus allows you to configure a goji middleware that logs all requests and responses using the structured logger logrus. It takes the logrus instance and the name of the app as the parameters and returns a middleware of type "func(http.Handler) http.Handler"
Example:
package main import( ""goji.io" "github.com/goji/glogrus2" "github.com/sirupsen/logrus" ) func main() { logr := logrus.New() logr.Formatter = new(logrus.JSONFormatter) goji.Use(glogrus.NewGlogrus(logr, "my-app-name")) goji.Get("/ping", yourHandler) goji.Serve() }
func NewGlogrusWithReqId ¶
func NewGlogrusWithReqId(l *logrus.Logger, name string, reqidf func(context.Context) string) func(http.Handler) http.Handler
NewGlogrusWithReqId allows you to configure a goji middleware that logs all requests and responses using the structured logger logrus. It takes the logrus instance, the name of the app and a function that can retrieve a requestId from the Context "func(context.Context) string" as the parameters and returns a middleware of type "func(http.Handler) http.Handler"
Passing in the function that returns a requestId allows you to "plug in" other middleware that may set the request id
Example:
package main import( ""goji.io" "github.com/goji/glogrus2" "github.com/sirupsen/logrus" ) func main() { logr := logrus.New() logr.Formatter = new(logrus.JSONFormatter) goji.Use(glogrus.NewGlogrusWithReqId(logr, "my-app-name", GetRequestId)) goji.Get("/ping", yourHandler) goji.Serve() } func GetRequestId(ctx context.Context) string { return ctx.Value("requestIdKey") }
Types ¶
This section is empty.