From 9e9217cc81ec461576062cb291dbcb3cb74b85a5 Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Thu, 2 Jun 2022 22:32:50 -0400 Subject: peach: add logging --- main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index c58839c..8aee763 100644 --- a/main.go +++ b/main.go @@ -86,6 +86,8 @@ func main() { // default handler. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + logRequest(r) + if r.URL.Path == "/" { http.Redirect(w, r, "/41.115,-83.177", 302) return @@ -149,6 +151,8 @@ func showWeather(w http.ResponseWriter, lat, lng float32) { } func showSearch(w http.ResponseWriter, r *http.Request) { + logRequest(r) + // Search is disabled if photon is not enabled. if !photon.Enabled() { http.NotFound(w, r) @@ -168,6 +172,8 @@ func showSearch(w http.ResponseWriter, r *http.Request) { } func serveStaticFile(w http.ResponseWriter, r *http.Request) { + logRequest(r) + // Add Cache-Control header w.Header().Set("Cache-Control", "max-age=604800") @@ -257,3 +263,7 @@ func NewSearch(r *http.Request) (*Search, error) { } return s, nil } + +func logRequest(r *http.Request) { + log.Printf("%v - %v", r.RemoteAddr, r.URL) +} -- cgit v1.2.3