:transform-fn
and :log-fn
optionstransform-fn
)Example:
(require '[clansi.core :as ansi])
(require '[timbre.core :as timbre])
(require '[ring.logger :refer [wrap-with-logger]])
(-> handler
(wrap-with-logger {:log-fn (fn [{:keys [level throwable message]}]
;; log using timbre instead of clojure.tools.logging
(timbre/log level throwable message))
:transform-fn (fn [log-item]
(if (get-in log-item [:message :status])
;; colorize the status code
(update-in log-item
[:message :status]
(fn [status]
(apply ansi/style
(str status)
(cond
(< status 300) [:default]
(>= status 500) [:bright :red]
(>= status 400) [:red]
:else [:yellow]))))
log-item))}))
wrap-with-logger
, 3 additional middlewares are provided to make it easier to choose what to log:
wrap-log-request-start
: logs the arrival of a request, adds :ring.logger/start-ms
key to the request mapwrap-log-request-params
: logs the parameters, using redaction to hide sensitive datawrap-log-response
: logs the response time and status, along with other data to identify the request. Uses
:ring.logger/start-ms
from the request map or calls (System/currentTimeMillis)
by itself.:redact-keys
accepts only keywords now. Strings are not accepted anymore.:exceptions
option to disable exception logging.
Useful when already using ring.middleware.stacktraceNew features:
:timing
option to disable logging timing informationBreaking changes:
:pre-logger
, :post-logger
and :exception-logger
were removed
They were intended as a way to override the way the messages are generated,
but we now have multimethods and :printer
to do that.The goal for this release was to refactor ring-logger and remove the timbre & onelog dependencies.
Breaking changes:
log
and add-extra-middleware
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close