File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6161; ; Logging
6262; ;
6363
64- (defn with-logging [handler]
65- (fn [^Exception e data req]
66- (logging/log! :error e (.getMessage e))
67- (handler e data req)))
64+ (defn with-logging
65+ " Wrap compojure-api exception-handler a function which will log the
66+ exception message and stack-trace with given log-level."
67+ ([handler] (with-logging handler :error ))
68+ ([handler log-level]
69+ {:pre [(#{:trace :debug :info :warn :error :fatal } log-level)]}
70+ (fn [^Exception e data req]
71+ (logging/log! log-level e (.getMessage e))
72+ (handler e data req))))
6873
6974; ;
7075; ; Mappings from other Exception types to our base types
Original file line number Diff line number Diff line change 7878 (without-err
7979 (fact " Logging can be added to a exception handler"
8080 (let [handler (-> (fn [_] (throw (ex-info " Error parsing request" {:type ::ex/request-parsing } (RuntimeException. " Kosh" ))))
81- (wrap-exceptions (assoc-in default-options [:handlers ::ex/request-parsing ] (ex/with-logging ex/request-parsing-handler))))]
82- (with-out-str (handler {})) => " ERROR Error parsing request\n " ))))
81+ (wrap-exceptions (assoc-in default-options [:handlers ::ex/request-parsing ] (ex/with-logging ex/request-parsing-handler :info ))))]
82+ (with-out-str (handler {})) => " INFO Error parsing request\n " ))))
You can’t perform that action at this time.
0 commit comments