pjlegato / ring.middleware.logger

Ring middleware to log each request
58 stars 24 forks source link

Ignore certain routes #10

Closed emlyn closed 9 years ago

emlyn commented 9 years ago

Is there a way to prevent logging of certain routes? I'm not interested in the health check requests from the load balancer, which are filling up the logs, is it possible to selectively disable them (or change the level)?

pjlegato commented 9 years ago

There's no way to do this from within r.m.logger itself, no.

I think the best way to implement this is as a small seperate "filter" middleware that would wrap r.m.logger. Modifying r.m.logger itself to know about routes would induce scope creep and a tighter coupling of r.m.logger to the routing engine. Keeping it seperate also allows it to be re-used for any other middleware someone might want to filter.

The filter would be something very simple, along the lines of:

(defn loggable-request?
  "Returns true if we want the given request to be logged"
  [request]
  ;; Analyze the the request here
  true)

(def website
   (-> routes
         (if-request-is loggable-request?
               wrap-with-logger)
          (wrap-with-authentication)))
pjlegato commented 9 years ago

I've just written https://github.com/pjlegato/ring.middleware.conditional , which permits you to specify arbitrary conditions and URL filtering for any middleware. This allows r.m.logger to remain focused only on logging issues, and also permits the re-use of filtering logic with any other middleware.

Could you please take a look and let me know whether this addresses your log filtering needs?

emlyn commented 9 years ago

Thanks, just got around to testing this now, it's just what I wanted.