accesslog

package module
v0.0.0-...-e339578 Latest Latest
Warning

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

Go to latest
Published: May 5, 2015 License: MIT Imports: 5 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Accesslog

Accesslog is a middleware for logging access with interfaces func(next http.Handler) http.Handler and HandlerFuncWithNext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc). See http://en.wikipedia.org/wiki/Common_Log_Format for log format.

Example

package main

import (
	"fmt"
	"github.com/vanng822/accesslog"
	"github.com/vanng822/r2router"
	"net/http"
	"log"
)

func main() {
	seefor := r2router.NewSeeforRouter()
	l := accesslog.New()
	seefor.Before(l.Handler)
	seefor.Get("/hello/:name", func(w http.ResponseWriter, r *http.Request, p r2router.Params) {
		fmt.Fprintf(w, "Hello %s!", p.Get("name"))
	})
	log.Fatal(http.ListenAndServe(":8080", seefor))
}

Documentation

Overview

Package accesslog logs request in standard format http://en.wikipedia.org/wiki/Common_Log_Format using interface Logger.Printf(format string, v ...interface{})

package main

import (
	"fmt"
	"github.com/vanng822/accesslog"
	"github.com/vanng822/r2router"
	"net/http"
)

func main() {
	seefor := r2router.NewSeeforRouter()
	log := accesslog.New()
	seefor.Before(log.Handler)
	seefor.Get("/user/keys/:id", func(w http.ResponseWriter, r *http.Request, p r2router.Params) {
		fmt.Fprint(w, p.Get("id"))
	})
	http.ListenAndServe(":8080", seefor)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

type Log struct {
	Logger Logger
}

func New

func New() *Log

func (*Log) Handler

func (l *Log) Handler(next http.Handler) http.Handler

Middleware implementing fun(next http.Handler) http.Handler

router := r2router.NewSeeforRouter() logger := accesslog.New() router.Before(logger.Handler)

func (*Log) HandlerFuncWithNext

func (l *Log) HandlerFuncWithNext(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Middleware implementing func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

n := negroni.New() logger := accesslog.New() n.UseFunc(logger.HandlerFuncWithNext)

type LogResponseWriter

type LogResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Wrap ResponseWriter for determination of status and content length

func (*LogResponseWriter) Write

func (lrw *LogResponseWriter) Write(b []byte) (int, error)

func (*LogResponseWriter) WriteHeader

func (lrw *LogResponseWriter) WriteHeader(status int)

type Logger

type Logger interface {
	Info(m string)
}

Logger defines needed interfaces One can use any logger with this interface

func WrapPrint

func WrapPrint(fn func(v ...interface{})) Logger

Wrap Print function of log.Logger or any similar function

func WrapSyslog

func WrapSyslog(fn func(m string) (err error)) Logger

Wrap any syslog.Writer function or any similar function

type LoggerFunc

type LoggerFunc func(m string)

Turn any logging function with this interface into Logger

func (LoggerFunc) Info

func (f LoggerFunc) Info(m string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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