apachelog

package module
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2017 License: MIT Imports: 15 Imported by: 10

README

go-apache-logformat

Build Status

GoDoc

Coverage Status

SYNOPSYS

import (
  "net/http"
  "os"

  "github.com/lestrrat/go-apache-logformat"
)

func main() {
  var s http.ServeMux
  s.HandleFunc("/", handleIndex)
  s.HandleFunc("/foo", handleFoo)

  http.ListenAndServe(":8080", apachelog.CombinedLog.Wrap(s, os.Stderr))
}

DESCRIPTION

This is a port of Perl5's Apache::LogFormat::Compiler to golang

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRuneSequence = errors.New("invalid rune sequence found in format")
	ErrUnimplemented       = errors.New("pattern unimplemented")
)
View Source
var CombinedLog, _ = New(`%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"`)

Combined is a pre-defined ApacheLog struct to log "combined" log format

View Source
var CommonLog, _ = New(`%h %l %u %t "%r" %>s %b`)

Combined is a pre-defined ApacheLog struct to log "common" log format

Functions

This section is empty.

Types

type ApacheLog

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

func New

func New(format string) (*ApacheLog, error)

New creates a new ApacheLog instance from the given format. It will return an error if the format fails to compile.

func (*ApacheLog) Wrap

func (al *ApacheLog) Wrap(h http.Handler, dst io.Writer) http.Handler

Wrap creates a new http.Handler that logs a formatted log line to dst.

func (*ApacheLog) WriteLog

func (al *ApacheLog) WriteLog(dst io.Writer, ctx LogCtx) error

WriteLog generates a log line using the format associated with the ApacheLog instance, using the values from ctx. The result is written to dst

type Format

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

Format describes an Apache log format. Given a logging context, it can create a log line.

func (*Format) WriteTo

func (f *Format) WriteTo(dst io.Writer, ctx LogCtx) error

type FormatWriteFunc

type FormatWriteFunc func(io.Writer, LogCtx) error

func (FormatWriteFunc) WriteTo

func (f FormatWriteFunc) WriteTo(dst io.Writer, ctx LogCtx) error

type FormatWriter

type FormatWriter interface {
	WriteTo(io.Writer, LogCtx) error
}

type LogCtx

type LogCtx interface {
	ElapsedTime() time.Duration
	Request() *http.Request
	RequestTime() time.Time
	ResponseContentLength() int64
	ResponseHeader() http.Header
	ResponseStatus() int
	ResponseTime() time.Time
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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