apachelog

package module
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: MIT Imports: 15 Imported by: ? modules, 0 packages

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

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
⌂ 换网址