logging

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSanitiser

func DefaultSanitiser() func(LogEntry) LogEntry

func GetSanitiser

func GetSanitiser(options SanitiserOptions) func(LogEntry) LogEntry

func MaskHeaders

func MaskHeaders(unmaskedHeaders map[string][]string, headersMask map[string]HeaderMask, isStrict bool) map[string][]string

func NewBatchLogger

func NewBatchLogger(options BatchLoggerOptions) *batchLogger

NewBatchLogger creates a new batchLogger with the provided options

Types

type BatchLoggerOptions

type BatchLoggerOptions struct {
	MaxBatchSize  int            // The maximum size of a batch in bytes
	MaxLogAge     time.Duration  // The maximum age of a log item in a batch - once an item is older than this, the batch is passed to the callback
	LogApiKey     string         // The API key used by the default BatchCallback used to send logs to the Firetail logging API
	LogApiUrl     string         // The URL of the Firetail logging API endpoint to send log entries to
	BatchCallback func([][]byte) // An optional callback to which batches will be passed; the default callback sends logs to the Firetail logging API
}

BatchLoggerOptions is an options struct used by the NewBatchLogger constructor

type HTTPProtocol

type HTTPProtocol string

The HTTP protocol used in the request

const (
	HTTP10 HTTPProtocol = "HTTP/1.0"
	HTTP11 HTTPProtocol = "HTTP/1.1"
	HTTP2  HTTPProtocol = "HTTP/2"
	HTTP3  HTTPProtocol = "HTTP/3"
)

type HeaderMask

type HeaderMask int
const (
	// If the mask is being applied strictly, then the header will be removed, otherwise it will be preserved
	UnsetHeader HeaderMask = iota

	// The header will be preserved and logged to FireTail as received
	PreserveHeader

	// The header will be removed entirely and not reported to Firetail
	RemoveHeader

	// The header value will be removed and not reported to FireTail
	RemoveHeaderValues

	// The header's value will hashed before it is reported to Firetail
	HashHeaderValues

	// Both the header's name and value will be hashed before being reported to Firetail
	HashHeader

	// Any of the header's values which match against a JWT pattern are removed
	RedactJWTSignature
)

type LogEntry

type LogEntry struct {
	DateCreated   int64    `json:"dateCreated"`   // The time the request was logged in UNIX milliseconds
	ExecutionTime float64  `json:"executionTime"` // The time elapsed during the execution required to respond to the request, in milliseconds
	Request       Request  `json:"request"`
	Response      Response `json:"response"`
	Version       Version  `json:"version"` // The version of the firetail logging schema used
}

All the information required to make a logging entry in Firetail

func UnmarshalLogEntry

func UnmarshalLogEntry(data []byte) (LogEntry, error)

func (*LogEntry) Marshal

func (r *LogEntry) Marshal() ([]byte, error)

type Method

type Method string

The request method. Src for allowed values can be found here: <a href='https://www.iana.org/assignments/http-methods/http-methods.xhtml#methods'>https://www.iana.org/assignments/http-methods/http-methods.xhtml#methods</a>.

const (
	ACL               Method = "ACL"
	BaselineControl   Method = "BASELINE-CONTROL"
	Bind              Method = "BIND"
	Checkin           Method = "CHECKIN"
	Checkout          Method = "CHECKOUT"
	Connect           Method = "CONNECT"
	Copy              Method = "COPY"
	Delete            Method = "DELETE"
	Empty             Method = "*"
	Get               Method = "GET"
	Head              Method = "HEAD"
	Label             Method = "LABEL"
	Link              Method = "LINK"
	Lock              Method = "LOCK"
	Merge             Method = "MERGE"
	Mkactivity        Method = "MKACTIVITY"
	Mkcalendar        Method = "MKCALENDAR"
	Mkcol             Method = "MKCOL"
	Mkredirectref     Method = "MKREDIRECTREF"
	Mkworkspace       Method = "MKWORKSPACE"
	Move              Method = "MOVE"
	Options           Method = "OPTIONS"
	Orderpatch        Method = "ORDERPATCH"
	Patch             Method = "PATCH"
	Post              Method = "POST"
	Pri               Method = "PRI"
	Propfind          Method = "PROPFIND"
	Proppatch         Method = "PROPPATCH"
	Put               Method = "PUT"
	Rebind            Method = "REBIND"
	Report            Method = "REPORT"
	Search            Method = "SEARCH"
	Trace             Method = "TRACE"
	Unbind            Method = "UNBIND"
	Uncheckout        Method = "UNCHECKOUT"
	Unlink            Method = "UNLINK"
	Unlock            Method = "UNLOCK"
	Update            Method = "UPDATE"
	Updateredirectref Method = "UPDATEREDIRECTREF"
	VersionControl    Method = "VERSION-CONTROL"
)

type Request

type Request struct {
	Body         string              `json:"body"`         // The request body, stringified
	Headers      map[string][]string `json:"headers"`      // The request headers
	HTTPProtocol HTTPProtocol        `json:"httpProtocol"` // The HTTP protocol used in the request
	IP           string              `json:"ip"`           // The source IP of the request
	Method       Method              `json:"method"`       // The request method. Src for allowed values can be found here: <a; href='https://www.iana.org/assignments/http-methods/http-methods.xhtml#methods'>https://www.iana.org/assignments/http-methods/http-methods.xhtml#methods</a>.
	URI          string              `json:"uri"`          // The URI the request was made to
	Resource     string              `json:"resource"`     // The resource path that the request matched up to in the OpenAPI spec
}

type Response

type Response struct {
	Body       string              `json:"body"`    // The response body, stringified
	Headers    map[string][]string `json:"headers"` // The response headers
	StatusCode int64               `json:"statusCode"`
}

type SanitiserOptions

type SanitiserOptions struct {
	// RequestHeadersMask is a map of header names (lower cased) to HeaderMask values, which can be used to control the request headers reported to Firetail
	RequestHeadersMask map[string]HeaderMask

	// RequestHeadersMaskStrict is an optional flag which, if set to true, will configure the Firetail middleware to only report request headers explicitly described in the RequestHeadersMask
	RequestHeadersMaskStrict bool

	// ResponseHeadersMask is a map of header names (lower cased) to HeaderMask values, which can be used to control the response headers reported to Firetail
	ResponseHeadersMask map[string]HeaderMask

	// ResponseHeadersMaskStrict is an optional flag which, if set to true, will configure the Firetail middleware to only report response headers explicitly described in the ResponseHeadersMask
	ResponseHeadersMaskStrict bool

	// RequestSanitisationCallback is an optional callback which is given the request body as bytes & returns a stringified request body which
	// is then logged to Firetail. This is useful for writing custom logic to redact any sensitive data from your request bodies before it is logged
	// in Firetail.
	RequestSanitisationCallback func(string) string

	// ResponseSanitisationCallback is an optional callback which is given the response body as bytes & returns a stringified response body which
	// is then logged to Firetail. This is useful for writing custom logic to redact any sensitive data from your response bodies before it is logged
	// in Firetail.
	ResponseSanitisationCallback func(string) string
}

DefaultSanitiserOptions is an options struct for the default sanitiser provided with Firetail.

type Version

type Version string

The version of the firetail logging schema used

const (
	The100Alpha Version = "1.0.0-alpha"
)

Jump to

Keyboard shortcuts

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