From a5e74338d495d42dfa1b0444082602cb4346dd8f Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Fri, 6 Oct 2023 02:28:29 -0400 Subject: [PATCH] added logging --- Dockerfile | 5 +++++ proxy.go | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0ddb0cd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM scratch + +COPY proxy /proxy + +ENTRYPOINT ["/proxy"] \ No newline at end of file diff --git a/proxy.go b/proxy.go index d5bafee..c2859f1 100644 --- a/proxy.go +++ b/proxy.go @@ -2,6 +2,7 @@ package simpleproxy import ( "io" + "log/slog" "net/http" "net/url" ) @@ -41,6 +42,9 @@ func (p *Proxy) ListenAndServe() error { // ServeHTTP is the main handler for the proxy server. // all requests here should be proxied to the server. func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { + logger := slog.Default().With("method", r.Method, "url", r.URL.String()) + + logger.Info("proxying request") // all requests should be proxied to the server. req, err := http.NewRequest(r.Method, p.ServerAddr+r.URL.String(), r.Body) if err != nil { @@ -61,6 +65,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + logger = slog.Default().With("status", resp.StatusCode) + mirrorResponse(w, resp) }