(ns sekai.core.logging
  (:require [sekai.core.gamestate :as gs :refer [game-state]]
            [sekai.util.util :as util]))

(def levels
  {:critical 0
   :error 1
   :warning 2
   :debug 3
   :info 4
   :verbose 5})

(def r-levels (util/reverse-map levels))

(defn set-level [level]
  (swap! game-state update-in [:settings] assoc :loglevel (levels level)))

(defn get-level-n []
  (-> @game-state :settings :loglevel))

(defn get-level []
  (r-levels (get-level-n)))

(defn should-log [level] (<= (levels level) (get-level-n)))

(defn log
  ([message] (log :debug message))
  ([level message]
   (when (should-log level) (println level "->" message))))
