Skip to content

Commit

Permalink
feat: Add .elin.edn
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Feb 2, 2024
1 parent 1ea0034 commit f5a9ddc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions .elin.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:log {:level :debug}}
18 changes: 10 additions & 8 deletions src/elin/core.clj
Original file line number Diff line number Diff line change
@@ -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))))
18 changes: 18 additions & 0 deletions src/elin/log.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f5a9ddc

Please sign in to comment.