convert info logs to debug to remove logging bloat

This commit is contained in:
flynn 2019-06-08 17:43:48 +02:00
parent 3e7b8a8b94
commit f8d26675df
8 changed files with 72 additions and 72 deletions

View file

@ -44,7 +44,7 @@
:min-lein-version "2.0.0"
:source-paths ["src/clj" "src/cljs" "src/cljc"]
:test-paths ["test/clj"]
:resource-paths ["resources" "target/cljsbuild"]
@ -63,7 +63,7 @@
:css-dirs ["resources/public/css"]
:nrepl-middleware
[cider/wrap-cljs-repl cider.piggieback/wrap-cljs-repl]}
:profiles
{:uberjar {:omit-source true
@ -81,8 +81,6 @@
:infer-externs true
:closure-warnings
{:externs-validation :off :non-standard-jsdoc :off}}}}}
:aot :all
:uberjar-name "cat.jar"
:source-paths ["env/prod/clj"]
@ -134,7 +132,7 @@
:main "cat.doo-runner"
:optimizations :whitespace
:pretty-print true}}}}}
:profiles/dev {}
:profiles/test {}}

View file

@ -47,7 +47,6 @@
{% if message %}
<h4 class="subtitle is-5 has-text-danger">{{message}}</h4>
{% endif %}
</div>
</div>
</div>

View file

@ -16,10 +16,10 @@
(mount/defstate ^{:on-reload :noop} http-server
:start
(http/start
(-> env
(assoc :handler #'handler/app)
(update :io-threads #(or % (* 2 (.availableProcessors (Runtime/getRuntime)))))
(update :port #(or (-> env :options :port) %))))
(-> env
(assoc :handler #'handler/app)
(update :io-threads #(or % (* 2 (.availableProcessors (Runtime/getRuntime)))))
(update :port #(or (-> env :options :port) %))))
:stop
(http/stop http-server))
@ -32,10 +32,9 @@
(when repl-server
(nrepl/stop repl-server)))
(defn stop-app []
(doseq [component (:stopped (mount/stop))]
(log/info component "stopped"))
(log/debug component "stopped"))
(shutdown-agents))
(defn start-app [args]
@ -63,4 +62,3 @@
(System/exit 0))
:else
(start-app args)))

View file

@ -2,7 +2,8 @@
(:require [cat.middleware :as middleware]
[cat.layout :refer [error-page]]
[cat.routes.home :refer [home-routes]]
[cat.routes.oauth :refer [oauth-routes admin-routes]]
[cat.routes.oauth :refer [oauth-routes]]
[cat.routes.admin :refer [admin-routes]]
[compojure.core :refer [routes wrap-routes]]
[ring.util.http-response :as response]
[compojure.route :as route]

View file

@ -18,8 +18,7 @@
; To authorize, redirect the user to the sign in / grant page
(defn- authorize-uri
[client-params ;csrf-token
]
[client-params #_csrf-token]
(str
(:authorize-uri client-params)
"?"
@ -41,7 +40,7 @@
"let the user authorize access by redirecting to the signin / grant page
of the used oauth api"
[]
(log/info "Oauth params: " (oauth2-params))
; (log/info "Oauth params: " (oauth2-params))
(authorize-uri (oauth2-params)))
(defn get-authentication-response
@ -50,7 +49,7 @@
(if (or true (= csrf-token state))
(try
(do
(log/info "Requesting access token with code " code)
(log/debug "Requesting access token with code " code)
(let [oauth2-params (oauth2-params)
access-token (httpclient/post (:access-token-uri oauth2-params)
{:form-params {:code code

View file

@ -0,0 +1,41 @@
(ns cat.routes.admin
(:require [cat.db.core :refer [*db*] :as db]
[compojure.core :refer [defroutes GET POST]]
[struct.core :as st]
[clojure.tools.logging :as log]
[ring.util.http-response :as response]))
(def user-schema
[[:name st/required st/string]
[:gender st/string]])
(def relation-schema
[[:from_id st/required st/integer-str]
[:to_id st/required st/integer-str]])
(defroutes admin-routes
(GET "/admin/enable" req (-> (response/found "/")
(assoc :session (assoc-in (:session req) [:user :admin :enabled] true))))
(GET "/admin/disable" req (-> (response/found "/")
(assoc :session (assoc-in (:session req) [:user :admin :enabled] false))))
(POST "/relations" req
(let [data (:params req) [err result] (st/validate data relation-schema)]
(log/info "Post to " (:uri req))
(if (nil? err)
(do
(db/create-relation! result)
(response/found "/"))
(do
(response/bad-request "Incorrect input")))))
(POST "/users" req
(let [data (:params req)]
(log/info "Post to " (:uri req))
(println data)
(if (st/valid? data user-schema)
(do
(db/create-user! (assoc data :zeusid nil))
(response/found "/"))
(do
(response/bad-request "Incorrect input")))))
)

View file

@ -9,14 +9,6 @@
[cat.layout :refer [error-page]]
[clojure.string :as s]))
(def user-schema
[[:name st/required st/string]
[:gender st/string]])
(def relation-schema
[[:from_id st/required st/integer-str]
[:to_id st/required st/integer-str]])
(def request_relation-schema
[[:to_id st/required st/integer-str]])
@ -53,7 +45,7 @@
rel-requests-out (seq (db/get-relation-requests-from-user {:from_id (:id user)}))
rel-requests-in (seq (db/get-relation-requests-to-user {:to_id (:id user)}))
non_requested_users (seq (filter (fn [other-user] (not (some (partial = (:id other-user)) (map :to_id rel-requests-out)))) other_users))]
(log/info (str "Session: " (:session req)))
(log/debug (str "Session: " (:session req)))
;(log/info (str "Relation requests: \n OUTGOING: " rel-requests-out "\n INCOMING: " rel-requests-in))
;(log/info (str "User relations: " user-relations))
;(log/info (str "Other Users: " other_users))
@ -118,7 +110,7 @@
(if (nil? from-id) (response/found (error-page
{:status 400
:title "No user id found in session"})))
(log/info "Post to " (:uri req) "\n with data " result)
(log/debug "Post to " (:uri req) "\n with data " result)
(if (nil? err)
(do
(log/debug "Create relation request")
@ -129,28 +121,7 @@
(do
(log/debug "Relation request failed")
(log/debug err)
(response/unprocessable-entity "Incorrect input")))))
; TODO make bottom 2 admin protected
(POST "/relations" req
(let [data (:params req) [err result] (st/validate data relation-schema)]
(log/info "Post to " (:uri req))
(if (nil? err)
(do
(db/create-relation! result)
(response/found "/"))
(do
(response/bad-request "Incorrect input")))))
(POST "/users" req
(let [data (:params req)]
(log/info "Post to " (:uri req))
(println data)
(if (st/valid? data user-schema)
(do
(db/create-user! (assoc data :zeusid nil))
(response/found "/"))
(do
(response/bad-request "Incorrect input"))))))
(response/unprocessable-entity "Incorrect input"))))))

View file

@ -10,13 +10,13 @@
(def admins [{:name "flynn" :zeusid 117}])
(defn set-user! [user session redirect-url]
(log/info "Set user in session: " user)
(log/debug "Set user in session: " user)
(let [new-session (-> session
(assoc :user user)
(cond-> (some (partial = (select-keys user [:zeusid :name])) admins)
(->
(assoc-in [:user :admin] {:enabled false})
(assoc :identity "foo"))))]
(->
(assoc-in [:user :admin] {:enabled false})
(assoc :identity "foo"))))]
(-> (found redirect-url)
(assoc :session new-session))))
@ -32,7 +32,7 @@
"Initiates the Twitter OAuth"
[request]
(let [reee (mo/authorize-api-uri)]
(log/info "authorize uri: " reee)
(log/debug "authorize uri: " reee)
(-> reee
found)))
@ -47,12 +47,12 @@
(assoc :flash {:denied true}))
; fetch the request token and do anything else you wanna do if not denied.
(let [{:keys [access_token refresh_token]} (mo/get-authentication-response nil req_token)]
(log/info "Successfully fetched access-id: " access_token)
(log/info "Fetching user info")
(log/debug "Successfully fetched access-id: " access_token)
(log/debug "Fetching user info")
(let [fetched-user (mo/get-user-info access_token)]
(log/info "Fetched user info: " fetched-user)
(log/debug "Fetched user info: " fetched-user)
(let [local-user (db/get-zeus-user {:zeusid (:id fetched-user)})]
(log/info "Zeus user from db: " local-user)
(log/debug "Zeus user from db: " local-user)
(if local-user
(set-user! local-user session "/")
(try
@ -60,16 +60,15 @@
:gender nil
:zeusid (:id fetched-user)}
generated-key (-> user-template
(db/create-user!,,,))]
(log/info "Created user: " generated-key)
(db/create-user!))]
(log/debug "Created user: " generated-key)
(set-user! (assoc user-template :id (:generated_key generated-key)) session "/"))
(catch Exception e
(do
(log/warn "fetched user" fetched-user "already exists, but was not found")
(log/warn (:cause (Throwable->map e)))
(-> (found "/")
(assoc :flash {:error "An error occurred, please try again."})))
))))))))
(assoc :flash {:error "An error occurred, please try again."})))))))))))
;(catch [:status 401] _
; (error-page {:status 401
@ -78,12 +77,6 @@
(defroutes oauth-routes
(GET "/oauth/oauth-init" req (oauth-init req))
(GET "/oauth/oauth-callback" [& req_token :as req] (oauth-callback req_token req))
(GET "/logout" req (clear-session! "/")))
(defroutes admin-routes
(GET "/admin/enable" req (-> (found "/")
(assoc :session (assoc-in (:session req) [:user :admin :enabled] true))))
(GET "/admin/disable" req (-> (found "/")
(assoc :session (assoc-in (:session req) [:user :admin :enabled] false)))))
(GET "/oauth/oauth-init" req (oauth-init req))
(GET "/oauth/oauth-callback" [& req_token :as req] (oauth-callback req_token req))
(GET "/logout" req (clear-session! "/")))