server

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BlocklistMirrorAccessLogFilePath = "crowdsec-blocklist-mirror_access.log"
View Source
var RouteHits = prometheus.NewCounterVec(
	prometheus.CounterOpts{
		Name: "blocklist_requests_total",
		Help: "Number of calls to each blocklist",
	},
	[]string{"route"},
)

Functions

func CombinedLoggingHandler

func CombinedLoggingHandler(out io.Writer, h http.Handler) http.Handler

CombinedLoggingHandler return a http.Handler that wraps h and logs requests to out in Apache Combined Log Format.

See http://httpd.apache.org/docs/2.2/logs.html#combined for a description of this format.

LoggingHandler always sets the ident field of the log to -

func CustomLoggingHandler

func CustomLoggingHandler(out io.Writer, h http.Handler, f LogFormatter) http.Handler

CustomLoggingHandler provides a way to supply a custom log formatter while taking advantage of the mechanisms in this package

func LoggingHandler

func LoggingHandler(out io.Writer, h http.Handler) http.Handler

LoggingHandler return a http.Handler that wraps h and logs requests to out in Apache Common Log Format (CLF).

See http://httpd.apache.org/docs/2.2/logs.html#common for a description of this format.

LoggingHandler always sets the ident field of the log to -

Example:

r := mux.NewRouter()
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("This is a catch-all route"))
})
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
http.ListenAndServe(":1123", loggedRouter)

func RunServer

func RunServer(ctx context.Context, g *errgroup.Group, config cfg.Config) error

Types

type LogFormatter

type LogFormatter func(writer io.Writer, params LogFormatterParams)

LogFormatter gives the signature of the formatter function passed to CustomLoggingHandler

type LogFormatterParams

type LogFormatterParams struct {
	Request    *http.Request
	URL        url.URL
	TimeStamp  time.Time
	StatusCode int
	Size       int
}

LogFormatterParams is the structure any formatter will be handed when time to log comes

Jump to

Keyboard shortcuts

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