gojilogger

package
v0.0.0-...-a92bcea Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2016 License: MIT, MIT Imports: 12 Imported by: 0

README

goji2-logger

GoDoc

Logging Middleware For Goji 2


import github.com/derekdowling/goji2-logger

// works with Logrus, stdlogger, most others as well
logger := New(os.Stderr, "", LstdFlags)
gojilogger.SetLogger(logger)

mux := goji.NewMux()
mux.UseC(gojilogger.Middleware)

Output looks like:

2015/12/16 16:55:21 Serving PATCH "/api/foos/1" from 127.0.0.1:57639
2015/12/16 16:55:21 Returning HTTP 200 after 53.044µs

Documentation

Index

Constants

View Source
const (
	// FastResponse is anything under this duration
	FastResponse = 500 * time.Millisecond
	// AcceptableResponse is anything under this duration
	AcceptableResponse = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// Logger is a https://github.com/derekdowling/go-stdlogger
	Logger std.Logger
	// Debug will increase verbosity of logging information, and causes Query params not
	// to be omitted. Do NOT use in production otherwise you risk logging sensitive
	// information.
	Debug bool
}

Logger contains instance state for a goji2logger to avoid configuration collisions if this middleware is used in multiple places

func New

func New(logger std.Logger, debug bool) *Logger

New creates a new goji2logger instance

func (*Logger) Middleware

func (l *Logger) Middleware(next goji.Handler) goji.Handler

Middleware logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return. When standard output is a TTY, Logger will print in color, otherwise it will print in black and white.

Use like so with Goji2:

gLogger := gojilogger.New(nil, false)
yourGoji.UseC(gLogger.Middleware)

Jump to

Keyboard shortcuts

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