Logging, awesome?

56 views
Skip to first unread message

LauJensen

unread,
Aug 30, 2009, 4:18:44 PM8/30/09
to Compojure
Hi group,

I decided that my new website, which is driven only by compojure,
needed a webcounter for statistics. From the top of my head I just
added this bit of code and I'd like some feedback. Is this awesome?

(defn log
[request]
(let [header (apply merge
(for [[k v] (:headers request)]
{(keyword k) v}))]
(run *mysql-connection*
(insert-into traffic [logged ~(java.util.Date.)
remote ~(:remote-addr request)
method ~(.toUpperCase (name
(:request-method request)))
query ~(:query-string request)
params ~(apply str (:route-params
request))
uri ~(:uri request)
referer ~(:referer header)
agent ~(:user-agent header)]))))

(defn with-logging
[handler]
(fn [request]
(log request)
(handler request)))

(run-server {:port 8888}
"/*"
(servlet
(with-logging
main-servlet)))

Lau

unread,
Aug 30, 2009, 5:03:03 PM8/30/09
to Compojure
By the by. If anyones interested, the site is up at

http://www.bestinclass.dk

/Lau
Reply all
Reply to author
Forward
0 new messages