whgls

package
v0.0.0-...-3f30213 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

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

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

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)))
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL