Skip to content

resurfaceio/logger-go

Repository files navigation

resurfaceio-logger-go

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

Go project version CodeFactor License Contributing

Contents

Requires go 1.18 or later.

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
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))
}

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.