This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-31
Channels
- # admin-announcements (4)
- # alda (3)
- # aws (1)
- # beginners (2)
- # boot (33)
- # braid-chat (4)
- # braveandtrue (20)
- # cider (52)
- # cljs-dev (13)
- # cljsrn (55)
- # clojure (111)
- # clojure-belgium (4)
- # clojure-brasil (6)
- # clojure-dusseldorf (1)
- # clojure-greece (116)
- # clojure-mexico (1)
- # clojure-nl (3)
- # clojure-russia (56)
- # clojure-spec (72)
- # clojure-uk (13)
- # clojurescript (66)
- # community-development (2)
- # component (24)
- # core-async (1)
- # cursive (19)
- # datomic (27)
- # devcards (5)
- # emacs (1)
- # funcool (34)
- # hoplon (313)
- # jobs (1)
- # lein-figwheel (11)
- # luminus (5)
- # mount (30)
- # off-topic (63)
- # om (375)
- # onyx (67)
- # perun (8)
- # proton (1)
- # reagent (4)
- # rum (1)
- # specter (55)
- # spirituality-ethics (7)
- # test-check (2)
- # untangled (34)
- # yada (20)
Hi guys, today trying a crazy thing again 🙂 I'm struggling with adding a all-handlers logging functionality, I'd like to trace the request and response for each one (including exceptions )
so far my way was adding a new step to the default-interceptor-chain
and was working fine until i tried to read the body of the request
this is my approach
if i comment the body related code
(when (= manifold.stream.BufferedStream (type (-> ctx :request :body)))
then it works fineon the contrary i get "error": "clojure.lang.ExceptionInfo: Malformed body {:status 400, :error (not (map? nil))}",
so it seems that once i read the body buffer something more happens that break later code
@tangrammer: here is our approach to request logging - it operates at the ring-with-maybe-deferred-responses level, rather than as a yada interceptor, since i wanted to log non-yada handlers too - but it may be useful nonetheless - https://www.refheap.com/119793
@tangrammer: Typically, the body of a request can on ly be read once. It may be large and span multiple buffers, or require multipart decoding. Hence you cannot read the request body more than once during a request. The sames goes for Ring. Where are logging? Current version of yada has an interceptor at the end that you can use (return)
I mean, it's called 'logging' and it will call any function you put in the resource's :logger entry.
It is also called in the error chain, so you can use it for logging exceptions too
I added this because of a request from @shmish111 and he has been able to use it
Great help! Thanks guys!!
Hi @malcolmsparks: using your approach
(defn log-handler [ctx]
(log/info "HANDLER LOGGER : " (:method ctx) (-> ctx :request :uri) " :::: " (-> ctx :parameters) )
ctx
)
{ ;; the yada resource here...
...
:logger log-handler
...
}
I don't get the parameters
that i should have in this loggin
step of the default-interceptor-chain
as far as this step is after parse-parameters
I mean that (-> ctx :parameters)
always returns nil
anyway i get the logger log/info calls but no parameters attached to the ctx
as normally i have inside the response fn for each resource
^i hope i could explain it well
@malcolmsparks: finally it seems an issue I'll create a github one with an reproducible example
if an error is thrown inside my response then my (-> ctx :parameters :body) => nil
even if the i/process-request-body
is passed through
@malcolmsparks: sorry for the noise, definitely the step wasn't reached in the interceptor chain and my problem was related with the schema validation I couldn't realise this error because i couldn't read the response/body in the logging interceptor-step without leaving unreadable the response to final api client (in this case a mobile client) Anyway, yada works fine 🙂 thanks!