http_logger

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LogBodiesOnError indicates to log bodies only for 4xx & 5xx errors
	LogBodiesOnErrors = 1 + iota
	// LogNoBody stipulates that we should never log bodies
	LogNoBody
	// LogAllBodies can be used to log all request bodies (use with care)
	LogAllBodies
)

// CONFIG ////

Variables

View Source
var NoBodyHTTPMethods = map[string]struct{}{
	"HEAD":    struct{}{},
	"OPTIONS": struct{}{},
	"GET":     struct{}{},
}

NoBodyHTTPMethods is the list of methods for which we don't log bodies cause they don't have any

Functions

func New

New returns an gin.HandlerFunc that will log our HTTP requests

Types

type AccessLog

type AccessLog struct {
	TimeStarted   string           `json:"start_time"`
	ClientAddress string           `json:"x_client_address,omitempty"`
	Time          int64            `json:"duration"`
	Request       RequestLogEntry  `json:"request"`
	Response      ResponseLogEntry `json:"response"`
	Errors        string           `json:"errors,omitempty"`
}

AccessLog describes the complete log entry format

type AccessLoggerConfig

type AccessLoggerConfig struct {
	Host           string
	Port           int
	Path           string
	DropSize       int
	MaxBodyLogSize int64
	BodyLogPolicy  int
	RetryInterval  time.Duration
	ExcludePaths   map[string]struct{}
	logger.Logger
}

AccessLoggerConfig describe the config of our access logger

type HTTPContent

type HTTPContent struct {
	Size     int64  `json:"size"`
	MimeType string `json:"mime_type,omitempty"`
	Content  string `json:"value,omitempty"`
}

HTTPContent describes the format of a Request body and it's metadata

type HTTPLogForwardingQueue

type HTTPLogForwardingQueue struct {
	Intake chan Log

	URL string
	// contains filtered or unexported fields
}

HTTPLogForwardingQueue forwards logs to an HTTP backend

func NewHTTPLogForwardingQueue

func NewHTTPLogForwardingQueue(conf AccessLoggerConfig) (q *HTTPLogForwardingQueue)

NewHTTPLogForwardingQueue builds a log forwarding queue that sends entries to an HTTP service, formatted as JSON

type LeechedGinResponseWriter

type LeechedGinResponseWriter struct {
	gin.ResponseWriter
	// contains filtered or unexported fields
}

LeechedGinResponseWriter is an extension of gin.ResponseWriter that logs the first bytes of the response body in a bytes buffer

func NewLeechedGinResponseWriter

func NewLeechedGinResponseWriter(source gin.ResponseWriter, maxSize int64) (newWriter *LeechedGinResponseWriter)

NewLeechedGinResponseWriter builds an returns a LeechedGinResponseWriter

func (*LeechedGinResponseWriter) Write

func (l *LeechedGinResponseWriter) Write(b []byte) (int, error)

Write stores up to maxSize bites that go through the original writer while writing them on the orginal writer

type LeechedReadCloser

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

LeechedReadCloser is a wrapper around io.ReadCloser that logs the first bytes of a Request's body (in our case) into a bytes buffer

func NewLeechedReadCloser

func NewLeechedReadCloser(source io.ReadCloser, maxSize int64) *LeechedReadCloser

NewLeechedReadCloser creates a readCloser which reads and stores at most maxSize bytes from a ReadCloser and returns a clone of that same reader, data included

func (*LeechedReadCloser) Close

func (l *LeechedReadCloser) Close() (err error)

Close closes on the original ReadCloser

func (*LeechedReadCloser) GetLog

func (l *LeechedReadCloser) GetLog() []byte

GetLog returns the captured log paylaod

func (*LeechedReadCloser) Read

func (l *LeechedReadCloser) Read(b []byte) (n int, err error)

Read reads stores up to maxSize bytes and keeps on reading

type Log

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

Log structure passed through the log forwarding channel

type LogForwardingQueue

type LogForwardingQueue interface {
	// contains filtered or unexported methods
}

LogForwardingQueue is a generic interface that forwards logs to a given output stream (stdout, http...)

type LoggerForwardingQueue

type LoggerForwardingQueue struct {
	Intake chan Log
	// contains filtered or unexported fields
}

func NewLoggerForwardingQueue

func NewLoggerForwardingQueue(conf AccessLoggerConfig) (q *LoggerForwardingQueue)

type RequestLogEntry

type RequestLogEntry struct {
	Method      string            `json:"method"`
	URI         string            `json:"uri"`
	HTTPVersion string            `json:"http_version"`
	Headers     map[string]string `json:"headers"`
	HeaderSize  int               `json:"headers_size"`
	Content     HTTPContent       `json:"content"`
}

RequestLogEntry describes the incoming requests log format

type ResponseLogEntry

type ResponseLogEntry struct {
	Status     int               `json:"status,omitempty"`
	Headers    map[string]string `json:"headers,omitempty"`
	HeaderSize int               `json:"headers_size"`
	Content    HTTPContent       `json:"content"`
}

ResponseLogEntry describes the server response log format

Jump to

Keyboard shortcuts

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