https://github.com/coast-framework/logger
12 factor ring logging middleware
https://github.com/coast-framework/logger
Last synced: about 1 year ago
JSON representation
12 factor ring logging middleware
- Host: GitHub
- URL: https://github.com/coast-framework/logger
- Owner: coast-framework
- License: mit
- Created: 2019-07-29T04:25:41.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-18T01:48:26.000Z (almost 7 years ago)
- Last Synced: 2025-05-17T10:08:32.413Z (about 1 year ago)
- Language: Clojure
- Size: 12.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logger
12 factor ring logging middleware
## Installation
Make your [deps.edn](https://clojure.org/guides/deps_and_cli) look like this:
```clojure
coast-framework/logger {:mvn/version "1.0.0"}
```
## Usage
Require it like this
```clojure
(ns your-project
(:require [logger.core :as logger]))
```
Log stuff like this, returns a string
```clojure
(logger/line "Request started" {"request-method" "GET" "uri" "/"})
; => "[timestamp] Request started request-method=GET" uri=/
(logger/line "Request finished" {"status" 200 "content-type" "text/plain"})
; => "[timestamp] Request finished status=200 content-type=text/plain"
```
Use the middleware like this
```clojure
(def app (-> (your-ring-app)
(logger/logger)))
```
This calls `println` twice and logs *two* ring request/response lines that look like this:
```
[timestamp] Request started request-method=GET route=home/index uri=/
[timestamp] Request finished status=200 duration=10ms content-type=text/html
```
*Note* route is only logged if there is a `:route` keyword in the request map
## Testing
```sh
cd logger && make test
```
## License
MIT
## Contribution
Create an issue, star it or make a pull request.