nberger / ring-logger

Log ring requests & responses using your favorite logging backend
Eclipse Public License 1.0
98 stars 20 forks source link

Avoid logging only request-params #25

Closed jcthalys closed 6 years ago

jcthalys commented 6 years ago

I'm implementing a custom printer multimethods to starting

(defmethod starting :my-starting
  [{:keys [logger] :as options} req]
  (info (ansi/style "Starting " :cyan)
        (select-keys req [:character-encoding
                          :content-length
                          :content-type
                          :query-string
                          :remote-addr
                          :request-method
                          :scheme
                          :server-name
                          :server-port
                          :uri
                          :identity])))

;;;
(wrap-with-logger {:printer :my-starting})

To avoid the others logs, I used only by the level of the log (request-details, sending-response), But the request-params it is also info as the startingand finished. So, How can I stop log this request-params?

nberger commented 6 years ago

@jcthalys one way (and the one I thought about when I decided to use multimethods for each kind of message) is to provide a "silent" request-params method for your printer, doing something like:

(defmethod messages/request-params :my-starting [_ _]
  ;; silent / do nothing
  )

Now you might want to rename my-starting to something else because it's not only about starting anymore, but that's a separate discussion that I'll leave to you :)

Does that work for you?

jcthalys commented 6 years ago

@nberger I'm sorry, but a couldn't understand how to use two custom :printer on this map that I'm passing to wrap-with-logger if I alright using the starting multimethod implementation?

How can I do to have the both implementations starting and request-params?

Thank you for the fast answer

nberger commented 6 years ago

@jcthalys you don't need to use two custom :printer, just a single one. The value passed as :printer in that map will be used to dispatch on the different multimethods defined in ring-logger.messages.

Maybe it's confusing and we should have used a protocol to group the 6 different messages (starting, request-details, request-params, sending-response, finished and exception). Or use a totally different approach. #21 is somewhat related to this, I hope to put some thinking on it soon. But for now the easier thing is to define the methods for your printer using defmethod and passing your printer dispatch value in the map.

Makes sense now?

jcthalys commented 6 years ago

perfectly clear now, so it worked, each one is a defmulti implementation that just made dispatch for the same name informed in :printer.

(defmethod messages/starting :monitoring-logger
  [{:keys [logger] :as options} req]
;; do samething
)

(defmethod messages/request-params :monitoring-logger [_ _]
  ;; silent / do nothing
  )

;;;;;;
(wrap-with-logger {:printer :monitoring-logger})

Thank you