   (:require
     ;; XXX Deprecate; use component config directly
     [clojure.core.async :as async :refer [chan >!! <!! >! <! go]]
-    [clojure.tools.logging :as log]
+    [taoensso.timbre :as log]
 
     [ring.component.jetty :as jetty]
     [com.stuartsierra.component :as component]

  [config opts app jetty-server]
  component/Lifecycle
  (start [component]
    (let [wrapped-handler (wrap-handler (:handler app))
          jetty-server (jetty/jetty-server (merge {:app (merge app {:handler wrapped-handler})}
                                                  (:server config)
                                                  opts))]
      (assoc component :jetty-server jetty-server)))
  (stop [component]
    (component/stop jetty-server)
    component))


(defn create-server
  ;; Default handler just return the healthcheck response always
  ([{:as opts :or {handler healthcheck-handler}}]
   (map->Server opts))
  ([]
   (create-server {})))

  "This wraps a handler such that requested for /healthcheck"
  [handler]
  (fn [{:as request :keys [uri]}]
    (if (= uri "/healthcheck")
      (healthcheck-handler request)
      (handler request))))
