Skip to content

Instantly share code, notes, and snippets.

@uwo
Forked from jcf/log.clj
Last active July 22, 2018 17:44
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 uwo/e98b012c0d9b4bfb4d3464c2ac1e5efd to your computer and use it in GitHub Desktop.
Save uwo/e98b012c0d9b4bfb4d3464c2ac1e5efd to your computer and use it in GitHub Desktop.
Refresh logback.xml from a Clojure REPL

deps.edn

{:deps {gist-uwo/logbacku {:git/url "https://gist.github.com/uwo/e98b012c0d9b4bfb4d3464c2ac1e5efd"
                          :sha "6febe8063e7189f39c1bdeb11db2e4ade519bcb8"}}}
{:paths ["."]
:deps {ch.qos.logback/logback-classic {:mvn/version "1.2.3"}}}
(ns logbacku
(:require [clojure.java.io :as io])
(:import ch.qos.logback.classic.joran.JoranConfigurator
ch.qos.logback.classic.LoggerContext
org.slf4j.LoggerFactory))
(defn reload-logback
"Load the given logback configuration file or reload the previously
loaded one if none is provided."
([]
(reload-logback (java.lang.System/getProperty "logback.configurationFile")))
([filepath]
(let [context ^LoggerContext (LoggerFactory/getILoggerFactory)
configurator (JoranConfigurator.)
config (io/file filepath)]
(assert config)
(.reset context)
(.setContext configurator context)
(.doConfigure configurator config)
{::reloaded-path filepath})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment