Comments (3)
By the way, any feedback about the 0.8.x approach will be much appreciated!
from ring-logger.
My 2 cents: a while ago I wanted to add some basic request/response logging to a small ring web app and looked into using this library. I wanted to have a single line per request with method + path + response status + elapsed time. I think there wasn't such a logger by default so I looked into writing a custom one but felt like it required too much code to pull it off.
What I ended up doing was looking at your source code and copying the bits I needed to write a single middleware function, which looked like this:
(defn- wrap-log-request
"Middleware that logs incoming requests."
[handler]
(fn [{:keys [request-method uri query-string] :as req}]
(let [start (System/currentTimeMillis)
method (-> request-method name str/upper-case)
path (if query-string (str uri "?" query-string) uri)
res (handler req)
time (- (System/currentTimeMillis) start)]
(log/info (format "%s %s [%d] (%dms)" method path (:status res) time))
res)))
from ring-logger.
@facundoolano thanks! I did more or less the same recently :).
In many cases it will be best to simply write your own middleware that way, but I think there's room for a library that provides logging middleware with a few more features (redacted params because you don't want sensitive information in your logs; colors because... well because colors are nice, but also because they make it easier to quickly identify some aspects of the output, especially if params were added to the output; request id to help correlate all the logs related to a request, etc.)
I recently needed to output json structured logs, to make it easier to extract metrics in the log processing pipeline. That's why I'm thinking in making the log to be just a map instead of a string, and let this output-fn
convert to whatever format is preferred. Final details are to be defined, maybe the output-fn
will actually be the logging middleware of which many will be provided, with a separate function/middleware/convention to take the timing metric and redact the params. The rest of the information is already in the request.
from ring-logger.
Related Issues (20)
- wrap-with-body logger missing timbre HOT 3
- Some params & headers should be redacted before being logged to hide sensitive information HOT 1
- Exception thrown on query params without a value HOT 4
- Options to set log level for starting and finished HOT 2
- Started using timbre ring-logger and seeing a mysterious nil printed at the start of each log line HOT 4
- Avoid logging only request-params HOT 4
- Filter query string HOT 4
- Redacted key is not removed from URL HOT 1
- Rewrite README for 1.0.0 HOT 1
- Add parameters redaction on 0.8.x HOT 1
- Add documentation using codox
- Migration from 0.7 to 1.0 HOT 1
- wrap-log-response HOT 1
- wrap-log-request-params doesn't work HOT 6
- No async support in 1.* version HOT 2
- Logging Request Body HOT 1
- Bump tools.logging to version 1.2.1 HOT 2
- Add a unique request-id as log context to identify multiple requests being logged concurrently
- Allow to disable logging of timing info
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ring-logger.