better logging

master
Clyne 2 years ago
parent 11ad43675f
commit 1ec46b5407
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -1,4 +1,4 @@
(defproject bitgloo-web "0.4" (defproject bitgloo-web "0.5"
:description "bitgloo website framework" :description "bitgloo website framework"
:url "https://bitgloo.com" :url "https://bitgloo.com"
:license {:name "GPL-3.0-or-later" :url "https://www.gnu.org/licenses/gpl-3.0.en.html"} :license {:name "GPL-3.0-or-later" :url "https://www.gnu.org/licenses/gpl-3.0.en.html"}

@ -35,15 +35,20 @@
(fn [request] (fn [request]
(when (= :get (:request-method request)) (handler request)))) (when (= :get (:request-method request)) (handler request))))
(defn wrap-log-request [handler] (defn wrap-log-transactions [handler]
(fn [request] (fn [request]
(-> request (let [response (handler request)]
(select-keys [:headers :protocol :request-method :uri]) (println
(update :headers get "x-forwarded-for") (get-in request [:headers "x-forwarded-for"])
(vals) "-"
(conj "request:") (str (java.util.Date.))
((partial apply println))) "-"
(handler request))) (:request-method request)
(:uri request)
(:protocol request)
"-"
(:status response))
response)))
(defn wrap-not-found [handler] (fn [request] (or (handler request) not-found))) (defn wrap-not-found [handler] (fn [request] (or (handler request) not-found)))
@ -58,7 +63,7 @@
(wrap-not-modified) (wrap-not-modified)
(wrap-only-gets) (wrap-only-gets)
(wrap-not-found) (wrap-not-found)
(wrap-log-request) (wrap-log-transactions)
(run-jetty {:port port}))) (run-jetty {:port port})))
(println "usage: bitgloo port content-path"))) (println "usage: bitgloo port content-path")))

Loading…
Cancel
Save