This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-28
Channels
- # announcements (6)
- # beginners (89)
- # boot (1)
- # calva (1)
- # cider (24)
- # cljsrn (19)
- # clojars (2)
- # clojure (102)
- # clojure-europe (2)
- # clojure-italy (9)
- # clojure-nl (1)
- # clojure-spec (6)
- # clojure-uk (56)
- # clojurescript (29)
- # code-reviews (14)
- # cursive (5)
- # data-science (1)
- # datomic (44)
- # duct (1)
- # emacs (10)
- # figwheel-main (5)
- # fulcro (8)
- # graphql (10)
- # hoplon (1)
- # leiningen (7)
- # overtone (17)
- # pathom (8)
- # re-frame (13)
- # slack-help (3)
- # spacemacs (22)
- # sql (2)
- # vim (3)
(let [start (System/currentTimeMillis)
response (atom nil)]
(try
(log/info "request:" url)
(reset! response (client/get url opts))
(:body @response)
(finally
(log/info "status" (:status @response) "duration:" (- (System/currentTimeMillis) start) "ms"))))
I'd probably use catch
clause and log "error" there and moved "info" log to the "happy path" flow.
The log would be somewhat duplicated but I guess you can create a little function to cover that.
(let [start (System/currentTimeMillis)
_ (log/info "request:" url)
response (try (client/get url opts) (catch Exception e …))]
(log/info "status" (:status response) "duration:" (- (System/currentTimeMillis) start) "ms")
(:body response))
In the ...
of the catch
you can log errors and/or return a response map with appropriate :status
and/or :body
fields.
^ @mping How does that look to you?
looks good; I would prefer to log the status and time at the same time so I dont have to use some correlation on the logs
That does log the status and time together.
(or are you concerned that the ...
error handling will take enough that that it would affect the millisecond timings?)