Skip to content

Instantly share code, notes, and snippets.

@jmorton
Created February 5, 2016 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmorton/719baeda698720e5635a to your computer and use it in GitHub Desktop.
Save jmorton/719baeda698720e5635a to your computer and use it in GitHub Desktop.
Setting log level example
(ns lcmap-data-clj.logger
(:require [clojure.logging.impl :as log-impl])
(:import [ch.qos.logback.classic Level]))
(comment "Usage example"
(set-level! 'lcmap-data-clj :debug)
(set-level! '[org.apache org.gdal] :info)
(set-level! '[com.datastax.driver co.paralleluniverse] :error))
(defn to-level [level]
(Level/toLevel (name level)))
(defn get-factory []
(log-impl/find-factory))
(defn get-logger [namespace]
(log-impl/get-logger (get-factory) namespace))
(defmulti set-level! (fn [scope level]
(mapv class [scope level])))
(defmethod set-level! [clojure.lang.Symbol clojure.lang.Keyword]
[ns level]
(.setLevel (get-logger ns) (to-level level)))
(defmethod set-level! [clojure.lang.PersistentVector clojure.lang.Keyword]
[ns-list level]
(doseq [ns ns-list]
(set-level! ns level)))
@oubiwann
Copy link

oubiwann commented Feb 5, 2016

I might rename to-level to some variation on level->keyword ...

I like your conversion of (dorun (map #(set-level! % level) namesps)) to (doseq ...)

@oubiwann
Copy link

oubiwann commented Feb 5, 2016

Woops, other way around: keyword->level.

I'm going to use this, but with multimethods ... so it will be a little different.

@oubiwann
Copy link

oubiwann commented Feb 5, 2016

That change has been pushed to Twig now -- note, however, that I didn't make the (deseq ...) change -- awaiting your PR/commit for that :-)

@oubiwann
Copy link

oubiwann commented Feb 7, 2016

As @yurrriq pointed out the other day, name actually handles all the cases I care about. (I had some bad code or data in the REPL session where I was testing and got misleading errors).

As such, I've removed the ->level multimethod implementation in twig and it now uses the same approach as defined by you here, simply calling (name ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment