# README
resurfaceio-logger-go
Easily log API requests and responses to your own security data lake.
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.
© 2016-2024 Graylog, Inc.
# Functions
get package global httpRules containing default rules sets.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewHttpLogger returns a pointer to a new HttpLogger object, with the given options applied, and an error.
NewHttpLoggerForMux returns a pointer to an instance of an HttpLoggerForMux struct with the default options applied and an error.
NewHttpLoggerForMuxOptions(o Options) returns a pointer to a HttpLoggerForMux struct with the given options o applied and an error.
No description provided by the author
NewNetHttpClientLogger() takes no arguments and returns 2 objects; a pointer to an instance of an NetHttpClientLogger struct and an 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.
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.
# Variables
No description provided by the author
# Structs
HttpLogger is the struct contains a pointer to a baseLogger instance and a set of rules used to define the behaviour of the logger.
No description provided by the author
No description provided by the author
struct for rules that are applied to http logging messages.
NetHttpClientLogger defines a struct used to log specifically from the client side of API interactions using the net/http package.
Options struct is passed to a "NewLogger" function to specify the desired configuration of the logger to be created.
No description provided by the author
No description provided by the author