Giter Site home page Giter Site logo

Comments (6)

EricBoersma avatar EricBoersma commented on September 3, 2024

Also seeing this same issue. No matter what I do, I can't get request params to log at all.

from ring-logger.

augusto-jm-amaral avatar augusto-jm-amaral commented on September 3, 2024

Same problem.

from ring-logger.

joefromct avatar joefromct commented on September 3, 2024

Depending on what you are doing you probably need to add the :request-keys to include maybe :body for a post.

Also, if you really want to see what's in body you'll probably have to slurp the content to get it visible as text. Of course, this will have overhead so i'm only doing things like this in dev.

Maybe something like this:

(defn compile-middleware [app]
  (-> app
      (logger/wrap-log-request-params {:log-fn (fn [{:keys [level throwable message]}]
                                                 (timbre/info level message throwable))
                                       :transform-fn #(-> %
                                                          (update-in  [:message :body] slurp)
                                                          clojure.pprint/pprint)
                                       :log-exceptions? true
                                       :log-level :info
                                       :request-keys  [:request-method :uri :server-name :headers :body]})
      maybe-wrap-basic-authentication
      maybe-wrap-reload))

from ring-logger.

ericnormand avatar ericnormand commented on September 3, 2024

It looks like you need to parse the query params (using ring.middleware.params/wrap-params). Ring doesn't parse the query string by default.

from ring-logger.

deobald avatar deobald commented on September 3, 2024

wrap-log-request-params does work but I just spent a minute battling with this because I had forgotten it makes some assumptions and doesn't (quite) work out-of-the-box. Here are the two thing you need to keep in mind:

  1. Middleware Order: Make sure wrap-params happens before wrap-log-request-params in the middleware lifecycle. Remember the order is bottom-up if you're using the threading macro (->).
  2. Log Level: By default, wrap-log-request-params logs to :debug and it's unlikely your local log config is set that high unless you're, well, debugging. Personally, I diagnose issues using param data all the time, so I bump the log level to :info.

Examples of these two notes follow

  1. Middleware Order example

This fails:

  (-> (handler)
      wrap-log-response
      wrap-keyword-params
      wrap-params
      wrap-log-request-params    ;; FAILS: this happens too early in the middleware lifecycle
      wrap-log-request-start)

This succeeds:

  (-> (handler)
      wrap-log-response
      wrap-log-request-params    ;; SUCCEEDS: the params have been parsed out of the request
      wrap-keyword-params
      wrap-params
      wrap-log-request-start)
  1. Log Level example

You can either bump your log level to DEBUG or use :transform-fn to adjust the log level of params logging before it hits the log-fn. I prefer the latter, since DEBUG tends to be very noisy:

(wrap-log-request-params {:transform-fn (fn [m] (assoc m :level :info))})

Hopefully this saves someone a minute or two. :)

@nberger I think you can close this issue. Maybe some of the resolving comments could go into the docs?

from ring-logger.

nberger avatar nberger commented on September 3, 2024

@deobald thanks for helping out here. You are correct, wrap-log-request-params depends on having wrap-params to parse the params first. That's what the example does too.

I agree it would be great to put some of this into the docs. Unfortunately I'm not having too much time to actively maintain the project lately. I made you a collaborator in case you'd like to make those additions yourself.

Thanks!

from ring-logger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.