logger-go
logger-go copied to clipboard
Log API calls with Go
resurfaceio-logger-go
Easily log API requests and responses to your own security data lake.
Contents
- Dependencies
- Installation
- Logging from gorilla/mux
- Protecting User Privacy
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.