diff --git a/src/blarg/handler.clj b/src/blarg/handler.clj index a848899..9aa7c7a 100644 --- a/src/blarg/handler.clj +++ b/src/blarg/handler.clj @@ -12,25 +12,18 @@ [blarg.views.layout :as layout] [blarg.models.db :as db] [blarg.routes.accessrules :refer [auth-required]] - [blarg.route-utils :refer [find-routes]])) + [blarg.route-utils :refer [find-routes]] + [blarg.util :refer [log-formatter]])) (defroutes app-routes (route/resources "/") (layout/render-handler "notfound.html" :status 404)) (defn init [] - (timbre/set-config! - [:appenders :rotor] - {:min-level :info - :enabled? true - :async? false ; should be always false for rotor - :max-message-per-msecs nil - :fn rotor/appender-fn}) - - (timbre/set-config! - [:shared-appender-config :rotor] - {:path "blarg.log" :max-size (* 512 1024) :backlog 10}) - + (timbre/set-config! [:shared-appender-config :spit-filename] "blarg.log") + (timbre/set-config! [:appenders :spit :enabled?] true) + (timbre/set-config! [:fmt-output-fn] log-formatter) + (timbre/info "blarg started successfully") (when (= "DEV" (config-val :env)) diff --git a/src/blarg/util.clj b/src/blarg/util.clj index 096c775..c521c25 100644 --- a/src/blarg/util.clj +++ b/src/blarg/util.clj @@ -1,5 +1,7 @@ (ns blarg.util - (:require [clojure.java.io :as io] + (:require [clojure.string :as str] + [clojure.java.io :as io] + [clojure.stacktrace :refer [print-stack-trace]] [markdown.core :as md] [noir.io] [cheshire.core :refer :all]) @@ -59,3 +61,13 @@ (defn ensure-prefix-suffix [s affix] (ensure-prefix (ensure-suffix s affix) affix)) + +(defn get-throwable-stack-trace [throwable] + (if throwable + (with-out-str + (print-stack-trace throwable)))) + +(defn log-formatter [{:keys [level throwable message timestamp hostname ns]} & [{:keys [nofonts?] :as appender-fmt-output-opts}]] + (format "%s %s %s [%s] - %s%s" + timestamp hostname (-> level name str/upper-case) ns (or message "") + (or (get-throwable-stack-trace throwable) ""))) \ No newline at end of file