webhelp.v1: gopkg.in/webhelp.v1/whgls Index | Files

package whgls

import "gopkg.in/webhelp.v1/whgls"

Package whgls provides webhelp tools that use grossness enabled by the github.com/jtolds/gls package. No other webhelp packages use github.com/jtolds/gls.

The predominant use case for github.com/jtolds/gls is to attach a current request's contextual information to all log lines kicked off by the request.

Index

Package Files

gls.go

func Bind Uses

func Bind(h http.Handler) http.Handler

Bind will make sure that Load works from any callstacks kicked off by this handler, via the magic of github.com/jtolds/gls. It is worthwhile to call Bind at the base of your handler stack and again after attaching any useful values you might want to include in logs to the request context.

func Load Uses

func Load() *http.Request

Load will return the *http.Request bound to the current call stack by a Bind handler further up the stack.

func SetLogOutput Uses

func SetLogOutput(
    logger func(ctx context.Context, format string, args ...interface{}))

SetLogOutput will configure the standard library's logger to use the provided logger that requires a context, such as AppEngine's loggers. This requires that the handler was wrapped with Bind. Note that this will cause all log messages without a context to be silently swallowed!

If whmon.RequestIds was in the handler callchain prior to Bind, this logger will also attach the Request ID to all log lines.

The benefit of this is that the standard library's logger (or some other logger that doesn't use contexts) can now be used naturally on a platform that requires contexts (like App Engine).

App Engine Example:

import (
  "net/http"

  "gopkg.in/webhelp.v1/whgls"
  "google.golang.org/appengine/log"
)

var (
  handler = ...
)

func init() {
  whgls.SetLogOutput(log.Infof)
  http.Handle("/", whmon.RequestIds(whgls.Bind(handler)))
}

Package whgls imports 7 packages (graph). Updated 2017-06-03. Refresh now. Tools for package owners.