Add more default keys, allow setting write-concern

This commit is contained in:
Emlyn Corrin 2013-06-05 18:19:18 +01:00
parent 0613ae66bb
commit 7cfae88eb3
1 changed files with 14 additions and 4 deletions

View File

@ -5,12 +5,21 @@
(def conn (atom nil)) (def conn (atom nil))
(def default-keys [:level :instant :ns :throwable :message]) ;; Note: including :throwable will fail with:
;; IllegalArgumentException: can't serialize class java.lang.Exception
(def default-keys [:hostname :ns :level :error? :instant :message :args])
(def default-args {:host "127.0.0.1" :port 27017}) (def default-args {:host "127.0.0.1" :port 27017})
(defn ensure-conn [{:keys [db server]}] (defn connect [{:keys [db server write-concern]}]
(let [args (merge default-args server)] (let [args (merge default-args server)
(swap! conn #(or % (mongo/make-connection db args))))) c (mongo/make-connection db args)]
(when write-concern
(mongo/set-write-concern c write-concern))
c))
(defn ensure-conn [config]
(swap! conn #(or % (connect config))))
(defn log-message [params {:keys [collection logged-keys] (defn log-message [params {:keys [collection logged-keys]
:or {logged-keys default-keys} :or {logged-keys default-keys}
@ -28,6 +37,7 @@
{:db \"logs\" {:db \"logs\"
:collection \"myapp\" :collection \"myapp\"
:logged-keys [:instant :level :message] :logged-keys [:instant :level :message]
:write-concern :acknowledged
:server {:host \"127.0.0.1\" :server {:host \"127.0.0.1\"
:port 27017}}") :port 27017}}")
:min-level :warn :enabled? true :async? true :min-level :warn :enabled? true :async? true