diff --git a/.elin.edn b/.elin.edn new file mode 100644 index 00000000..2daba2f4 --- /dev/null +++ b/.elin.edn @@ -0,0 +1 @@ +{:log {:level :debug}} diff --git a/src/elin/core.clj b/src/elin/core.clj index e2f09261..92e442e3 100644 --- a/src/elin/core.clj +++ b/src/elin/core.clj @@ -1,18 +1,20 @@ (ns elin.core (:require [com.stuartsierra.component :as component] + [elin.config :as e.config] [elin.log :as e.log] [elin.system :as e.system])) (defn -main - [host port development-mode] + [host port current-working-directory] (let [port (Long/parseLong port) - develop? (= "true" development-mode) - sys-map (e.system/new-system {:develop? develop? - :server {:host host - :port port}})] - (when develop? - (alter-var-root #'e.log/log-level (constantly e.log/DEBUG_LEVEL))) - (e.log/debug "elin.core Starting server:" (pr-str port) "\n\n\n") + config (->> {:server {:host host :port port}} + (e.config/load-config current-working-directory)) + sys-map (e.system/new-system config)] + + (when-let [level (get-in config [:log :level])] + (e.log/set-level! level)) + + (e.log/debug "elin.core Starting server:" (pr-str config) "\n\n\n") (component/start-system sys-map) (deref (promise)))) diff --git a/src/elin/log.clj b/src/elin/log.clj index 60e7b438..c2471703 100644 --- a/src/elin/log.clj +++ b/src/elin/log.clj @@ -11,6 +11,24 @@ (def log-level INFO_LEVEL) (def ^:dynamic *log-file* "/tmp/elin.log") +(defn set-level! + [level] + (let [level (cond + (int? level) + level + + (keyword? level) + (case level + :debug DEBUG_LEVEL + :info INFO_LEVEL + :warning WARNING_LEVEL + :error ERROR_LEVEL + INFO_LEVEL) + + :else + INFO_LEVEL)] + (alter-var-root #'log-level (constantly level)))) + (defn log [& messages] (let [s (->> (map str messages)