apachelog

package module
v0.0.0-...-8ba44a3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2016 License: MIT Imports: 5 Imported by: 0

README

apachelog Build Status GoDoc Coverage Status Go Report Card

Apache style logging middleware for your proxies. Uses apachelog.

Installation

go get -u gopkg.in/vinxi/apachelog.v0

API

See godoc reference.

Example

Default log to stdout
package main

import (
  "fmt"
  "gopkg.in/vinxi/apachelog.v0"
  "gopkg.in/vinxi/vinxi.v0"
)

const port = 3100

func main() {
  // Create a new vinxi proxy
  vs := vinxi.NewServer(vinxi.ServerOptions{Port: port})
  
  // Attach the log middleware 
  vs.Use(log.Default)
  
  // Target server to forward
  vs.Forward("http://httpbin.org")

  fmt.Printf("Server listening on port: %d\n", port)
  err := vs.Listen()
  if err != nil {
    fmt.Errorf("Error: %s\n", err)
  }
}
Using a custom io.Writer
package main

import (
  "fmt"
  "os"
  "gopkg.in/vinxi/apachelog.v0"
  "gopkg.in/vinxi/vinxi.v0"
)

const port = 3100

func main() {
  // Create a new vinxi proxy
  vs := vinxi.NewServer(vinxi.ServerOptions{Port: port})
  
  // Attach the log middleware 
  vs.Use(log.New(os.Stdout))
  
  // Target server to forward
  vs.Forward("http://httpbin.org")

  fmt.Printf("Server listening on port: %d\n", port)
  err := vs.Listen()
  if err != nil {
    fmt.Errorf("Error: %s\n", err)
  }
}

License

MIT

Documentation

Index

Constants

View Source
const Version = "0.1.0"

Version defines the current package semantic version.

Variables

View Source
var Default = New(os.Stdout)

Default provides a default logger middleware who writes into stdout.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger represents the log layer who writes to the given io.Writer.

func New

func New(w io.Writer) *Logger

New creates a new log middleware.

func (*Logger) LogHTTP

func (l *Logger) LogHTTP(h http.Handler) func(w http.ResponseWriter, r *http.Request)

LogHTTP instruments and logs an incoming HTTP request and response.

func (*Logger) Register

func (l *Logger) Register(mw layer.Middleware)

Register registers the log middleware handler.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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