Note: if you just want something that will execute at startup and
force _all_ logging to use log4j, instead of wrapping code in (binding
..) then you probably want something like this:

(ns your.namespace
  (:require [clojure.tools.logging :as log])
  (:require [clojure.tools.logging.impl :as impl]))

(alter-var-root (var log/*logger-factory*) (constantly (impl/log4j-factory)))

This is what we ended with in our code to ensure log4j was selected at
startup...

Sean

On Thu, Nov 17, 2011 at 7:04 PM, Mark Rathwell <mark.rathw...@gmail.com> wrote:
> You rebind dynamic vars with binding, so your use would look something
> like this:
>
> (binding [*logger-factory* (log-impl/log4j-factory)]
>  (do-stuff-with-the-logger-factory-rebound))
>
>
> On Thu, Nov 17, 2011 at 5:17 PM, vitalyper <vitaly...@yahoo.com> wrote:
>> clojure.tools.logging defines *logger-factory* and initializes it with
>> first logger implementation on the class path
>>
>> (def ^{:doc
>>  "An instance satisfying the impl/LoggerFactory protocol. Used
>> internally to
>>   obtain an impl/Logger. Defaults to the value returned from impl/
>> find-factory."
>>  :dynamic true}
>>  *logger-factory*
>>  (impl/find-factory))
>>
>> In my own namespace I want to redefine *logger-factory* to log4j one.
>> Tried different variations (def, set!, etc) in 1.3.0 with no avail.
>> (ns my.foo
>>  (:gen-class)
>>  (:use
>>    [clojure.tools.logging :only (*logger-factory* info debug)])
>>  (:require
>>            [clojure.string :as s1]
>>            [clojure.tools.logging.impl :as log-impl])
>> )
>>
>> (defn init-logging
>>  "Force log4j factory for core tools logging"
>>  []
>>  (def *logger-factory* (log-impl/log4j-factory)))
>> ; CompilerException java.lang.IllegalStateException: *logger-factory*
>> already refers to: #'clojure.tools.logging/*logger-factory* in
>> namespace: infrared.common

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to