log

package
v0.0.0-...-93f7a3c Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLine = errors.New("Invalid Line")

ErrInvalidLine is the error if the line supplied did not match the regex

Functions

This section is empty.

Types

type Channel

type Channel chan Line

Channel is a channel that accepts LogLines

func (Channel) Tail

func (lc Channel) Tail(reader *bufio.Reader)

Tail will listen on the reader and send all Lines into the Channel This should be run within a goroutine

type Line

type Line struct {
	IPAddress  string
	Identity   string
	UserID     string
	Date       time.Time
	Request    LineRequest
	StatusCode int
	Size       int
}

Line is a data structure that holds parsed information about a w3c-formatted HTTP access log (https://en.wikipedia.org/wiki/Common_Log_Format)

func NewLine

func NewLine(raw string) (Line, error)

NewLine returns a Line from a raw string

func RandomLine

func RandomLine() Line

RandomLine returns a randomly generated Line.

func (*Line) Send

func (l *Line) Send(c Channel)

Send sends the Line into the Channel

func (*Line) String

func (l *Line) String() string

type LineRequest

type LineRequest struct {
	Method   string
	URL      string
	Protocol string
}

LineRequest is the portion of the log line which contains request line from the client. It includes method of the request, the resource requested, and the HTTP protocol.

func NewLineRequest

func NewLineRequest(raw string) *LineRequest

NewLineRequest returns a LineRequest from a raw string

func (*LineRequest) Section

func (lr *LineRequest) Section() (string, error)

Section returns what's before the second '/' in the URL's path. For example, the section for "http://my.site.com/pages/create” is "http://my.site.com/pages".

func (*LineRequest) String

func (lr *LineRequest) String() string

type Lines

type Lines []Line

Lines is a typalias for a list so methods can be used against it

func (*Lines) Clear

func (ll *Lines) Clear()

Clear ...

func (Lines) ClearBefore

func (ll Lines) ClearBefore(t time.Time) Lines

ClearBefore returns a new Lines with all entries with a date before time t removed TODO: clear in place

func (*Lines) ErrorCode4XX

func (ll *Lines) ErrorCode4XX() int

ErrorCode4XX returns the number of logs that have an error code 4xx

func (*Lines) ErrorCode5XX

func (ll *Lines) ErrorCode5XX() int

ErrorCode5XX returns the number of logs that have an error code 5xx

func (Lines) Len

func (ll Lines) Len() int

Len is part of sort.Interface.

func (Lines) Less

func (ll Lines) Less(i, j int) bool

Less is part of sort.Interface. Sort by Date

func (*Lines) MostActiveUser

func (ll *Lines) MostActiveUser() (string, int)

MostActiveUser returns the user with the most requests and the number of requests

func (*Lines) SectionWithMostHits

func (ll *Lines) SectionWithMostHits() (string, int)

SectionWithMostHits returns the request section that has the largest occurrence and the number of time it appears (hits)

func (Lines) Swap

func (ll Lines) Swap(i, j int)

Swap is part of sort.Interface.

Jump to

Keyboard shortcuts

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