Skip to content

goji/glogrus2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

goji/glogrus GoDoc

glogrus2 provides structured logging via logrus for Goji2.

Example

Simple logging

package main

import(
	"github.com/goji/glogrus2"
    "goji.io"
    "net/http"
    "github.com/Sirupsen/logrus"
)

func main() {
    router := goji.NewMux()
	logr := logrus.New()
	logr.Formatter = new(logrus.JSONFormatter)
	goji.Use(glogrus.NewGlogrus(logr, "my-app-name"))

	log.Fatal(http.ListenAndServe(":8080", router))
}

Logging with custom request id from http Context

package main

import(
	"github.com/goji/glogrus2"
    "goji.io"
    "golang.org/x/net/context"
    "net/http"
    "github.com/Sirupsen/logrus"
)

func main() {
    router := goji.NewMux()
	logr := logrus.New()
	logr.Formatter = new(logrus.JSONFormatter)
	router.UseC(glogrus.NewGlogrusWithReqId(logr, "my-app-name", IdFromContext))

	log.Fatal(http.ListenAndServe(":8080", router))
}

func IdFromContext(ctx context.Context) string {
    return ctx.Value("requestIdKey")
}

Need something to put requestId in your Context?

gojiid can help you with that

Looking for hierarchical structured logging?

slog and lunk looks interesting.

About

Logrus logging for Context-based Goji

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages