sbsdev / mdr2

Production Management Tool for DAISY Talking Books
GNU Affero General Public License v3.0
0 stars 0 forks source link

More logging #84

Closed egli closed 1 year ago

egli commented 1 year ago
egli commented 1 year ago

A simple way to log all requests would be with a ring request logger such as Ring-logger

modified   project.clj
@@ -50,6 +50,7 @@
                  [ring-webjars "0.2.0"]
                  [ring/ring-core "1.9.5"]
                  [ring/ring-defaults "0.3.3"]
+                 [ring-logger "1.1.1"]
                  [selmer "1.12.53"]
                  [thheller/shadow-cljs "2.19.0" :scope "provided"]
                  [toyokumo/tarayo "0.2.5"]
modified   src/clj/mdr2/middleware.clj
@@ -18,6 +18,7 @@
     [ring.middleware.defaults :refer [site-defaults wrap-defaults]]
     [ring.middleware.flash :refer [wrap-flash]]
     [ring.util.http-response :refer [forbidden unauthorized]]
+    [ring.logger :as ring-log :refer [wrap-with-logger]]
     [iapetos.collector.ring :as prometheus]
     [mdr2.metrics :as metrics]))

@@ -99,6 +100,8 @@
         (-> site-defaults
             (assoc-in [:security :anti-forgery] false)
             (dissoc :session)))
+      (wrap-with-logger {:transform-fn (fn [{{type ::ring-log/type} :message :as msg}] (condp = type :finish msg  :exception msg nil))
+                         :status-to-log-level-fn (fn [status] (if (and (number? status) (<= 500 status)) :error :debug))})
       (prometheus/wrap-metrics
        metrics/registry {:path "/metrics"})
       wrap-internal-error))

OTOH I'm not so sure if we want to log each and every request in the log file.