logger

package module
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: Apache-2.0 Imports: 23 Imported by: 1

README

resurfaceio-logger-go

Easily log API requests and responses to your own security data lake.

Go project version CodeFactor License Contributing

Contents

Dependencies

Requires go 1.18 or later.

Installation

Run this command in the same directory as your project's go.mod and go.sum files:

go get github.com/resurfaceio/logger-go/v3

Logging from gorilla/mux

package main

import (
	"log"
	"net/http"

	"github.com/gorilla/mux"
	"github.com/resurfaceio/logger-go/v3" //<----- 1
)


func main() {
	router := mux.NewRouter()
  
	options := logger.Options{ //<----- 2
		Rules:   "include_debug\n",
		Url:     "http://localhost:7701/message",
		Enabled: true,
		Queue:   nil,
	}

	httpLoggerForMux, err := logger.NewHttpLoggerForMuxOptions(options) //<----- 3

	if err != nil {
		log.Fatal(err)
	}

	router.Use(httpLoggerForMux.LogData) //<----- 4

	log.Fatal(http.ListenAndServe(":5000", router))
}

Protecting User Privacy

Loggers always have an active set of rules that control what data is logged and how sensitive data is masked. All of the examples above apply a predefined set of rules, include_debug, but logging rules are easily customized to meet the needs of any application.

Logging rules documentation


© 2016-2024 Graylog, Inc.

Documentation

Overview

Package logger-go from resurface.io provides tools to log API requests and responses from different Golang web frameworks to a complete API system of record. (https://resurface.io)

Index

Constants

This section is empty.

Variables

View Source
var LIMIT = 1024 * 1024

Functions

func MockGetBrotliResponse added in v3.2.3

func MockGetBrotliResponse(request *http.Request) http.Response

func MockGetDeflateResponse added in v3.2.3

func MockGetDeflateResponse(request *http.Request) http.Response

func MockGetGzipResponse added in v3.2.3

func MockGetGzipResponse(request *http.Request) http.Response

func MockGetJPEGResponse added in v3.2.3

func MockGetJPEGResponse(request *http.Request) http.Response

func MockGetJSONEncodedResponse added in v3.2.3

func MockGetJSONEncodedResponse(request *http.Request, encoding string) http.Response

func MockGetJSONResponse added in v3.2.3

func MockGetJSONResponse(request *http.Request) http.Response

func MockGetNoBodyRequest added in v3.2.3

func MockGetNoBodyRequest() http.Request

func MockGetNoBodyResponse added in v3.2.3

func MockGetNoBodyResponse(request *http.Request) http.Response

func MockGetPlainTextResponse added in v3.2.3

func MockGetPlainTextResponse(request *http.Request) http.Response

func MockGetRequestWithBody added in v3.2.3

func MockGetRequestWithBody(body []byte, mimeType string) http.Request

func MockGetResponseWithBody added in v3.2.3

func MockGetResponseWithBody(request *http.Request, body []byte, mimeType string) http.Response

func SendHttpMessage

func SendHttpMessage(logger *HttpLogger, resp *http.Response, req *http.Request, now int64, interval int64, customFields map[string]string)

SendHttpMessage(l *HttpLogger, resp *http.Response, req *http.Request, now int64, interval int64) Uses logger l to send a log of the given resp and req to the loggers url here, now refers to the time at which the request was received and interval corresponds to the time between request and response. customFields are used to pass custom information fields through the logger to Resurface.

Types

type HttpLogger

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

HttpLogger is the struct contains a pointer to a baseLogger instance and a set of rules used to define the behaviour of the logger.

func NewHttpLogger

func NewHttpLogger(options Options) (*HttpLogger, error)

NewHttpLogger returns a pointer to a new HttpLogger object, with the given options applied, and an error

func (HttpLogger) Disable

func (logger HttpLogger) Disable()

func (HttpLogger) Enable

func (logger HttpLogger) Enable()

func (HttpLogger) Enabled

func (logger HttpLogger) Enabled() bool

func (HttpLogger) Queue

func (logger HttpLogger) Queue() []string

func (*HttpLogger) Stop added in v3.3.1

func (logger *HttpLogger) Stop()

type HttpLoggerForMux

type HttpLoggerForMux struct {
	HttpLogger *HttpLogger
	// contains filtered or unexported fields
}

HttpLoggerForMux defines a struct used to log specifically gorilla/mux apps

func NewHttpLoggerForMux

func NewHttpLoggerForMux() (*HttpLoggerForMux, error)

NewHttpLoggerForMux returns a pointer to an instance of an HttpLoggerForMux struct with the default options applied and an error. If there is no error, the error value returned will be nil.

func NewHttpLoggerForMuxOptions

func NewHttpLoggerForMuxOptions(options Options) (*HttpLoggerForMux, error)

NewHttpLoggerForMuxOptions(o Options) returns a pointer to a HttpLoggerForMux struct with the given options o applied and an error. If there is no error, the error value returned will be nil.

func (HttpLoggerForMux) LogData

func (muxLogger HttpLoggerForMux) LogData(next http.Handler) http.Handler

LogData() takes 1 argument of type http.Handler and returns an object of the same type, http.Handler. This function is intended to be used in a Middleware function in a gorilla/mux server. For details on how to set up Middleware for a mux server see: https://github.com/resurfaceio/logger-go#logging_from_mux

type HttpRule

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

func NewHttpRule

func NewHttpRule(_verb string, _scope *regexp.Regexp,
	_param1 interface{}, _param2 interface{}) *HttpRule

type HttpRules

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

struct for rules that are applied to http logging messages

func GetHttpRules

func GetHttpRules() *HttpRules

get package global httpRules containing default rules sets

func (*HttpRules) AllowHttpUrl

func (rules *HttpRules) AllowHttpUrl() bool

func (*HttpRules) CopySessionField

func (rules *HttpRules) CopySessionField() []*HttpRule

func (*HttpRules) DebugRules

func (rules *HttpRules) DebugRules() string

func (*HttpRules) DefaultRules

func (rules *HttpRules) DefaultRules() string

func (*HttpRules) Remove

func (rules *HttpRules) Remove() []*HttpRule

func (*HttpRules) RemoveIf

func (rules *HttpRules) RemoveIf() []*HttpRule

func (*HttpRules) RemoveIfFound

func (rules *HttpRules) RemoveIfFound() []*HttpRule

func (*HttpRules) RemoveUnless

func (rules *HttpRules) RemoveUnless() []*HttpRule

func (*HttpRules) RemoveUnlessFound

func (rules *HttpRules) RemoveUnlessFound() []*HttpRule

func (*HttpRules) Replace

func (rules *HttpRules) Replace() []*HttpRule

func (*HttpRules) Sample

func (rules *HttpRules) Sample() []*HttpRule

func (*HttpRules) SetDefaultRules

func (rules *HttpRules) SetDefaultRules(r string)

*HttpRules.SetDefaultRules(r string) sets the default rules of the logger to rule(s) r

func (*HttpRules) Size

func (rules *HttpRules) Size() int

func (*HttpRules) SkipCompression

func (rules *HttpRules) SkipCompression() bool

func (*HttpRules) SkipSubmission added in v3.3.1

func (rules *HttpRules) SkipSubmission() bool

func (*HttpRules) StandardRules

func (rules *HttpRules) StandardRules() string

func (*HttpRules) Stop

func (rules *HttpRules) Stop() []*HttpRule

func (*HttpRules) StopIf

func (rules *HttpRules) StopIf() []*HttpRule

func (*HttpRules) StopIfFound

func (rules *HttpRules) StopIfFound() []*HttpRule

func (*HttpRules) StopUnless

func (rules *HttpRules) StopUnless() []*HttpRule

func (*HttpRules) StopUnlessFound

func (rules *HttpRules) StopUnlessFound() []*HttpRule

func (*HttpRules) StrictRules

func (rules *HttpRules) StrictRules() string

func (*HttpRules) Text

func (rules *HttpRules) Text() string

type NetHttpClientLogger

type NetHttpClientLogger struct {
	http.Client
	HttpLogger *HttpLogger
}

NetHttpClientLogger defines a struct used to log specifically from the client side of API interactions using the net/http package.

func NewNetHttpClientLogger

func NewNetHttpClientLogger() (*NetHttpClientLogger, error)

NewNetHttpClientLogger() takes no arguments and returns 2 objects; a pointer to an instance of an NetHttpClientLogger struct and an error. The NetHttpClientLogger returned by this function has the default options applied. If there is no error, the error value returned will be nil.

func NewNetHttpClientLoggerOptions

func NewNetHttpClientLoggerOptions(options Options) (*NetHttpClientLogger, error)

NewNetHttpClientLoggerOptions() takes 1 argument of type logger.Options and returns 2 objects; a pointer to an instance of an NetHttpClientLogger struct and an error. The NetHttpClientLogger returned by this function has the given options applied. If there is no error, the error value returned will be nil.

func (*NetHttpClientLogger) CloseIdleConnections

func (clientLogger *NetHttpClientLogger) CloseIdleConnections()

net.http.Client.CloseIdleConnections() wrapper

func (*NetHttpClientLogger) Do

func (clientLogger *NetHttpClientLogger) Do(req *http.Request) (resp *http.Response, err error)

net.http.Client.Do wrapper with logging

func (*NetHttpClientLogger) Get

func (clientLogger *NetHttpClientLogger) Get(url string) (resp *http.Response, err error)

net.http.Client.Get wrapper with logging

func (*NetHttpClientLogger) Head

func (clientLogger *NetHttpClientLogger) Head(url string) (resp *http.Response, err error)

net.http.Client.Head wrapper with logging

func (*NetHttpClientLogger) Logger

func (logger *NetHttpClientLogger) Logger() *HttpLogger

func (*NetHttpClientLogger) Post

func (clientLogger *NetHttpClientLogger) Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)

net.http.Client.Post wrapper with logging

func (*NetHttpClientLogger) PostForm

func (clientLogger *NetHttpClientLogger) PostForm(url string, data url.Values) (resp *http.Response, err error)

net.http.Client.PostForm wrapper with logging

type Options

type Options struct {
	//Rules defines the rules that will be applied to the logger.
	Rules string

	//Url defines the Url the logger will send the logs to.
	Url string

	//Enabled defines the state of the logger; enabled or disabled.
	Enabled interface{}

	//Queue is a slice of strings used to store logs; exclusively for testing purposes.
	//Queue must be nil for the logger to properly function.
	Queue []string
}

Options struct is passed to a "NewLogger" function to specify the desired configuration of the logger to be created.

type TLSConfig added in v3.4.0

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

type UsageLoggers

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

func GetUsageLoggers

func GetUsageLoggers() (*UsageLoggers, error)

func (*UsageLoggers) ConfigByDefault added in v3.3.1

func (uLogger *UsageLoggers) ConfigByDefault() map[string]int

* * Returns additional configuration for the base logger

func (*UsageLoggers) Disable

func (uLogger *UsageLoggers) Disable()

* * Disable all usage loggers.

func (*UsageLoggers) Enable

func (uLogger *UsageLoggers) Enable()

* * Enable all usage loggers, except those explicitly disabled.

func (*UsageLoggers) IsEnabled

func (uLogger *UsageLoggers) IsEnabled() bool

* * Returns true if usage loggers are generally enabled.

func (*UsageLoggers) TLSConfigByDefault added in v3.4.0

func (uLogger *UsageLoggers) TLSConfigByDefault() TLSConfig

* * Returns additional TLS configuration for the internal http client

func (*UsageLoggers) UrlByDefault

func (uLogger *UsageLoggers) UrlByDefault() string

* * Returns url to use by default.

Jump to

Keyboard shortcuts

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