              :info  Level/INFO
              :warn  Level/WARNING
              :error Level/SEVERE})
+
+(def REVERSE-LEVELS (apply hash-map (flatten (map reverse LEVELS))))
 
 (def DEFAULT-LEVEL :warn)
 

     :author "Jeff Rose"}
  overtone.util.log
  (:import [java.util.logging Logger Level ConsoleHandler FileHandler
            StreamHandler SimpleFormatter])
  (:use [overtone.config store]))

; Sets up some basic logging infrastructure and helpers for the project.

(defonce LOGGER (Logger/getLogger "overtone"))

(defonce LOG-APPEND false)
(defonce LOG-CONSOLE (ConsoleHandler.))

(def LOG-FILE-HANDLER (FileHandler. OVERTONE-LOG-FILE LOG-APPEND))

      (assert (contains? LEVELS lvl))
      (.setLevel LOGGER (lvl LEVELS)))))

(defn- log-formatter []
  (proxy [Formatter] []
    (format [^LogRecord log-rec]
      (let [lvl (REVERSE-LEVELS (.getLevel log-rec))
            msg (.getMessage log-rec)
            ts (.getMillis log-rec)]
        (with-out-str (pprint {:level lvl
                               :timestamp ts
                               :date (Date. (long ts))
                               :msg msg}))))))

(defn- print-handler []
  (let [formatter (log-formatter)]
    (proxy [StreamHandler] []
      (publish [msg] (println (.format formatter msg))))))

