Skip to content

Commit

Permalink
logging: Add basic logging middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
goshatch committed Sep 9, 2024
1 parent 57ffaeb commit e0006bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/apossiblespace/parts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
["/register"
{:post {:handler account/register-account}}]]]]
{:data {:middleware [middleware/exception
middleware/logging
[wrap-json-body {:keywords? true}]
wrap-json-response
auth/wrap-jwt-authentication]}})
Expand Down
8 changes: 8 additions & 0 deletions src/apossiblespace/parts/api/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@
{:status 500
:body {:error "Internal server error"}})
})))

(defn logging
[handler]
(fn [request]
(let [user-id (get-in request [:identity :sub])
authenticated? (boolean user-id)]
(mulog/log ::request :request request, :authenticated? authenticated? :user-id user-id)
(handler request))))

0 comments on commit e0006bf

Please sign in to comment.