-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting log level for log-requests from configuration #20
Supporting log level for log-requests from configuration #20
Conversation
68dee99
to
2940593
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. This seems a reasonable change. I've reviewed the code and made some comments.
src/duct/middleware/web.clj
Outdated
(defn- log-request | ||
([logger request] | ||
(log-request logger request :info)) | ||
([logger request level] | ||
(logger/log logger level ::request (select-keys request request-log-keys)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a private function, so it doesn't need two different arities. Also take care to ensure that lines are indented correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing.
I delete older [logger request]
arity. Now there is only `[logger request level]'.
I also reformatted my code with cljfmt.
src/duct/middleware/web.clj
Outdated
(fn | ||
([request] | ||
(log-request logger request) | ||
(log-request logger request (or level :info)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
level
is :info
by default, so there's no need to check for nil
at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
I removed (or ...)
and change it to (log-request logger request level)
.
src/duct/module/web.clj
Outdated
(defn- logging-config [config] | ||
{:duct.middleware.web/log-requests (or (:duct.middleware.web/log-requests config) {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the purpose of these changes. Why not just let the configurations merge normally? Why add this exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
That is my misunderstand of configuration.
Now I rollbacked original code.
And I added test code for changing log level via config in test/duct/module/web_test.clj
.
Also, can you change the commit message to:
|
425282c
to
288762c
Compare
src/duct/middleware/web.clj
Outdated
(defn- log-request | ||
([logger request level] | ||
(logger/log logger level ::request (select-keys request request-log-keys)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the unnecessary ()
. e.g.
(defn- log-request [logger level request]
(logger/log logger :info ::request (select-keys request request-log-keys)))
src/duct/middleware/web.clj
Outdated
(defmethod ig/init-key ::log-requests [_ {:keys [logger level]}] | ||
#(wrap-log-requests % logger level)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a default for log levels here. e.g.
(defmethod ig/init-key ::log-requests
[_ {:keys [logger level] :or {level :info}}]
#(wrap-log-requests % logger level))
src/duct/module/web.clj
Outdated
@@ -34,7 +34,7 @@ | |||
|
|||
(def ^:private logging-config | |||
{:duct.middleware.web/log-requests {} | |||
:duct.middleware.web/log-errors {} | |||
:duct.middleware.web/log-errors {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure your diff doesn't include unnecessary spacing alterations.
test/duct/module/web_test.clj
Outdated
(is (= {:urlencoded true :keywordize false} | ||
(:params (:duct.middleware.web/defaults config')))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure your diff doesn't include unnecessary spacing alterations.
test/duct/middleware/web_test.clj
Outdated
(let [logs (atom []) | ||
handler (wrap-log-requests (constantly response) (->TestLogger logs) :trace)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the let
clauses are correctly aligned, and the lines are 80 characters or under.
943c43e
to
2268e28
Compare
Thank you for reviewing again. |
src/duct/middleware/web.clj
Outdated
(defn- log-request | ||
[logger request level] | ||
(logger/log logger level ::request (select-keys request request-log-keys))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to put [logger request level]
on a new line.
test/duct/middleware/web_test.clj
Outdated
(let [logs (atom []) | ||
handler (wrap-log-requests (constantly response) | ||
(->TestLogger logs) :trace)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reformat according to style guidelines. i.e.
(let [logs (atom [])
handler (wrap-log-requests (constantly response)
(->TestLogger logs)
:trace)]
test/duct/module/web_test.clj
Outdated
{:duct.middleware.web/log-requests {:level :debug}}) | ||
config' (core/build-config config)] | ||
(is (= {:level :debug} | ||
(:duct.middleware.web/log-requests (:duct.middleware.web/defaults config')))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure lines are within 80 characters.
2268e28
to
f6b1524
Compare
Thank you. |
test/duct/middleware/web_test.clj
Outdated
(let [logs (atom []) | ||
handler (wrap-log-requests (constantly response) | ||
(->TestLogger logs) | ||
:trace)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per my last comment, could you fix the spacing in the let
clause? There are 2 spaces after handler
instead of 1. Otherwise it looks fine.
f6b1524
to
79dc5a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, sorry for the delay. I've been busy working on fixing an issue in Ring. Now that I've come back to it, I've noticed that wrap-log-requests
is a public function, and that we should probably use an option map instead, so we that don't have to change the API if we want to add any more functionality. Apologies for not thinking about that sooner.
src/duct/middleware/web.clj
Outdated
(handler request respond raise)))) | ||
([handler logger] | ||
(wrap-log-requests handler logger :info)) | ||
([handler logger level] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that to future-proof this API, it would make sense to make the third argument an options map. So instead of level
, change it to {:keys [level] :or {level :info}}
. Then in the ::log-requests
method we can pass the options directly, minus the logger: (dissoc options :logger)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you reply (and also contributing to Ring. We all clojurian thank a lot for your work).
I pushed new commit with your feedback.
I added third parameter to wrap-log-requests
function as an option map.
And I revised test-wrap-log-requests
to add a third parameter.
(We always call wrap-log-requests
with three parameters. Is it correct?)
79dc5a0
to
dabd146
Compare
Hi, how's it going? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for forgetting about this PR! Feel free to poke me whenever I take too long. I've looked it over, and I think after the change I've outlined it should be good to merge. Thanks for your work on this.
src/duct/middleware/web.clj
Outdated
|
||
(defn- log-error [logger ex] | ||
(logger/log logger :error ::handler-error ex)) | ||
|
||
(defn wrap-log-requests | ||
"Log each request using the supplied logger. The logger must implement the | ||
duct.core.protocols/Logger protocol." | ||
[handler logger] | ||
[handler logger {:keys [level] :or {level :info}}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add in a 2-arity version with a blank map? i.e.
(defn wrap-log-requests
"..."
([handler logger]
(wrap-log-requests handler logger {}))
([handler logger {:keys [level] :or {level :info}}]
...))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I will do it.
test/duct/middleware/web_test.clj
Outdated
(testing "asynchronous" | ||
(let [logs (atom []) | ||
handler (wrap-log-requests | ||
(fn [_ respond _] (respond response)) | ||
(->TestLogger logs)) | ||
(->TestLogger logs) {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This {}
can be removed when you have a default options argument.
dabd146
to
fe9a616
Compare
Thanks again for your work on this. Sorry it took so long to merge. |
Thank you for merging my PR. |
Add new configuration feature to modify log-requests' log level.
You can modify requests log level in your config like ...
Also you can hide all requests log like ...