   ([{:keys [file] :or {file "log/cook.log"} {:keys [default] :or {default :info} :as overrides} :levels}]
    (try
      (.. (org.apache.log4j.Logger/getRootLogger)
-       (getLoggerRepository)
-       (resetConfiguration))
-   ;; This lets you inspect which loggers have which appenders turned on
-   ;;(clojure.pprint/pprint (map #(select-keys % [:allAppenders :name]) (log4j-conf/get-loggers)))
-   (let [overrides (->> overrides
-                        (filter (comp string? key))
-                        (mapcat (fn [[logger level]]
-                                  [[logger] {:level level}])))]
-     (apply log4j-conf/set-loggers!
-            (org.apache.log4j.Logger/getRootLogger)
-            {:out (org.apache.log4j.DailyRollingFileAppender.
-                    (org.apache.log4j.PatternLayout.
-                      "%d{ISO8601} %-5p %c [%t] - %m%n")
-                    file
-                    "'.'yyyy-MM-dd")
-             :level default}
-            overrides))
+         (getLoggerRepository)
+         (resetConfiguration))
+     ;; This lets you inspect which loggers have which appenders turned on
+     ;;(clojure.pprint/pprint (map #(select-keys % [:allAppenders :name]) (log4j-conf/get-loggers)))
+     (let [overrides (->> overrides
+                          (filter (comp string? key))
+                          (mapcat (fn [[logger level]]
+                                    [[logger] {:level level}])))]
+       (apply log4j-conf/set-loggers!
+              (org.apache.log4j.Logger/getRootLogger)
+              {:out (org.apache.log4j.DailyRollingFileAppender.
+                      (org.apache.log4j.PatternLayout.
+                        "%d{ISO8601} %-5p %c [%t] - %m%n")
+                      file
+                      "'.'yyyy-MM-dd")
+               :level default}
+              overrides))
      (catch Throwable t
        (.println System/err "Failed to initialize logging!")
        (.printCauseTrace t)

    {:mesos-datomic mesos-datomic
     :route full-routes
     :http-server (fnk [[:settings server-port authorization-middleware [:rate-limit user-limit]] [:route view]]
                       (log/info "Launching http server")
                       (let [rate-limit-storage (storage/local-storage)
                             jetty ((lazy-load-var 'qbits.jet.server/run-jetty)
                                    {:port server-port
                                     :ring-handler (-> view
                                                       tell-jetty-about-usename
                                                       (wrap-rate-limit {:storage rate-limit-storage
                                                                         :limit user-limit})
                                                       authorization-middleware
                                                       wrap-stacktrace
                                                       wrap-no-cache
                                                       wrap-cookies
                                                       wrap-params
                                                       health-check-middleware
                                                       instrument)
                                     :join? false
                                     :configurator configure-jet-logging
                                     :max-threads 200
                                     :request-header-size 32768})]
                         (fn [] (.stop jetty))))

     :framework-id (fnk [curator-framework [:settings mesos-leader-path]]
                        (when-let [bytes (curator/get-or-nil curator-framework
                                                             (str mesos-leader-path "/framework-id"))]
                          (String. bytes)))
     :mesos-datomic-mult (fnk [mesos-datomic]
                              (first ((lazy-load-var 'cook.datomic/create-tx-report-mult) mesos-datomic)))
     :local-zookeeper (fnk [[:settings zookeeper-server]]
                           (when zookeeper-server
                             (log/info "Starting local ZK server")
                             (.start zookeeper-server)))
     :mesos mesos-scheduler
     :mesos-pending-jobs-atom (fnk [] (atom {}))
     :mesos-offer-cache (fnk [[:settings [:offer-cache max-size ttl-ms]]]


(def mesos-datomic
  (fnk [[:settings mesos-datomic-uri]]
    ((lazy-load-var 'datomic.api/create-database) mesos-datomic-uri)
    (let [conn ((lazy-load-var 'datomic.api/connect) mesos-datomic-uri)]
      (doseq [txn (deref (lazy-load-var 'cook.mesos.schema/work-item-schema))]
        (deref ((lazy-load-var 'datomic.api/transact) conn txn))
        ((lazy-load-var 'metatransaction.core/install-metatransaction-support) conn)
        ((lazy-load-var 'metatransaction.utils/install-utils-support) conn))
      conn)))

(def curator-framework
  (fnk [[:settings zookeeper] local-zookeeper]
    (let [retry-policy (BoundedExponentialBackoffRetry. 100 120000 10)
          ;; The 180s session and 30s connection timeouts were pulled from a google group
          ;; recommendation
          curator-framework (CuratorFrameworkFactory/newClient zookeeper 180000 30000 retry-policy)
          ]
      (.. curator-framework
          getConnectionStateListenable
          (addListener (reify ConnectionStateListener
                         (stateChanged [_ client newState]
                           (log/info "Curator state changed:"
                                     (str newState))))))
      (.start curator-framework)
      curator-framework)))

(defn tell-jetty-about-usename [h]
  "Our auth in cook.spnego doesn't hook in to Jetty - this handler
