From 1ec46b5407ac719bc85019a791511d0f5df1d6f5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 22 May 2023 10:28:21 -0400 Subject: [PATCH] better logging --- project.clj | 2 +- src/bitgloo_web/core.clj | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/project.clj b/project.clj index 538a8fd..9db96b3 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject bitgloo-web "0.4" +(defproject bitgloo-web "0.5" :description "bitgloo website framework" :url "https://bitgloo.com" :license {:name "GPL-3.0-or-later" :url "https://www.gnu.org/licenses/gpl-3.0.en.html"} diff --git a/src/bitgloo_web/core.clj b/src/bitgloo_web/core.clj index ba34e71..bd4ba6b 100644 --- a/src/bitgloo_web/core.clj +++ b/src/bitgloo_web/core.clj @@ -35,15 +35,20 @@ (fn [request] (when (= :get (:request-method request)) (handler request)))) -(defn wrap-log-request [handler] +(defn wrap-log-transactions [handler] (fn [request] - (-> request - (select-keys [:headers :protocol :request-method :uri]) - (update :headers get "x-forwarded-for") - (vals) - (conj "request:") - ((partial apply println))) - (handler request))) + (let [response (handler request)] + (println + (get-in request [:headers "x-forwarded-for"]) + "-" + (str (java.util.Date.)) + "-" + (:request-method request) + (:uri request) + (:protocol request) + "-" + (:status response)) + response))) (defn wrap-not-found [handler] (fn [request] (or (handler request) not-found))) @@ -58,7 +63,7 @@ (wrap-not-modified) (wrap-only-gets) (wrap-not-found) - (wrap-log-request) + (wrap-log-transactions) (run-jetty {:port port}))) (println "usage: bitgloo port content-path")))