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
Add :io.pedestal.http/request-logger
to your service map
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)))