Skip to content

Commit

Permalink
introduce env-config.impl.report
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Oct 16, 2016
1 parent de9191d commit 5181af9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/lib/env_config/impl/report.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(ns env-config.impl.report
(:require [clojure.string :as string]
[env-config.impl.logging :as logging]))

(def ^:dynamic *message-prefix* "env-config: ")
(def ^:dynamic *reports* nil) ; should be bound if reporting is desired

; -- reporting --------------------------------------------------------------------------------------------------------------

(defn apply-prefix [message]
(str *message-prefix* message))

(defn report-warning! [message]
(if *reports*
(swap! *reports* conj [:warn (apply-prefix message)]))
nil)

(defn report-error! [message]
(if *reports*
(swap! *reports* conj [:error (apply-prefix message)]))
nil)

(defn report-info! [message]
(if *reports*
(swap! *reports* conj [:info (apply-prefix message)]))
nil)

; -- standard logging -------------------------------------------------------------------------------------------------------

(defn log-reports-if-needed! [reports & [reporter]]
(if (and (or (nil? reporter) (fn? reporter)) (not (empty? reports)))
(let [effective-reporter (or reporter logging/reporter)]
(effective-reporter reports))))

0 comments on commit 5181af9

Please sign in to comment.