Releases: nberger/ring-logger
Releases · nberger/ring-logger
1.1.1
New features
- Added :status-to-level-fn, which allows you to control the logging level of HTTP status codes in wrap-log-response.
Enhancements
- Added support for async ring handlers
- Async handlers were supported in 0.7, but support was dropped in 1.0.0.
- This change should make it easy to migrate to 1.x from 0.7
- Updated org.clojure/tools.logging dependency to 1.2.3 (thanks @CambodianCoder)
What's Changed
- Clarifying docs around
wrap-log-request-params
by @deobald in #47 - Add support for async middleware by @Kauko in #49
- Status to level config by @Kauko in #50
- Update project.clj by @CambodianCoder in #53
- Hide warnings in tests about shadowing clojure.core by @miikka in #54
- Fix async tools-logging-test by @miikka in #56
New Contributors
- @deobald made their first contribution in #47
- @Kauko made their first contribution in #49
- @CambodianCoder made their first contribution in #53
- @miikka made their first contribution in #54
Full Changelog: 1.0.1...1.1.1
1.0.1
1.0.0
This is a major, breaking-changes release
- Logger protocol and messages multimethod ("printer") were replaced with
:transform-fn
and:log-fn
options - No default coloring (coloring can be added through the
transform-fn
) - "Logs as data": Log messages are simple clojure maps now. This makes it easy to transform to different
final representations: string, colored string, JSON, EDN, etc.
Some rationale behind this release: #30
Example using timbre and clansi for coloring:
(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))}))
New features
- Apart from
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.