This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-29
Channels
- # aleph (5)
- # announcements (2)
- # bangalore-clj (2)
- # beginners (52)
- # cider (10)
- # cljsrn (1)
- # clojure (160)
- # clojure-dev (24)
- # clojure-europe (3)
- # clojure-france (1)
- # clojure-india (1)
- # clojure-italy (3)
- # clojure-nl (6)
- # clojure-spec (13)
- # clojure-uk (51)
- # clojurescript (45)
- # code-reviews (1)
- # core-async (41)
- # cursive (41)
- # datomic (17)
- # emacs (37)
- # fulcro (42)
- # graphql (7)
- # joker (4)
- # music (1)
- # nrepl (2)
- # off-topic (21)
- # pathom (19)
- # pedestal (12)
- # re-frame (48)
- # reitit (6)
- # rewrite-clj (8)
- # shadow-cljs (41)
- # specter (6)
- # sql (21)
- # tools-deps (8)
- # vim (7)
- # xtdb (27)
I want to add custom logging
The goal is basically to ignore requests from a certain IP range
(Kubernetes master calling “/”)
I’ve got some Ring middleware to do that
Is there a way to include that in Pedestal?
Now I see this:
INFO io.pedestal.http - {:msg "GET /", :line 80}
INFO io.pedestal.http - {:msg "GET /", :line 80}
INFO io.pedestal.http - {:msg "GET /", :line 80}
...
That needs to goMiddleware looks like this:
(defn logging-middleware [handler]
(-> handler
(middleware.conditional/if not-request-from-internal-ip? wrap-with-info-logger)))
@erwinrooijakkers you can provide your own request logger. See https://github.com/pedestal/pedestal/blob/master/service/src/io/pedestal/http.clj#L205-L206
thanks 🙂
Works like a charm
For those interested:
(defn- from-internal-ip?
"Returns truthy when a request does not come from an internal IP (e.g., a
Kubernetes node)"
[{:keys [server-name] :as request}]
(let [internal-ip-start "10."]
(string/starts-with? (str server-name) internal-ip-start)))
(def log-request
"Log the request's method and uri."
(interceptor.helpers/on-request
::log-request
(fn [request]
(when-not (from-internal-ip? request)
(log/info :msg (format "%s %s"
(string/upper-case (name (:request-method request)))
(:uri request))))
request)))