Re: Change var in other namespace
this reply was god sent to me. I use tomcat and war to deploy my clojure code. the default thing was just not compiling. Although I do not have slf4j in my classpath. find logger was still giving slf4j and when it encountered first logging statement, the code used to crap out saying class not found exception On Saturday, 19 November 2011 06:17:13 UTC+5:30, Sean Corfield wrote: On Fri, Nov 18, 2011 at 6:35 AM, vitalyper vita...@yahoo.comjavascript: wrote: IMO, clojure.tools.logging could of made this easier: log implementation from classpath by default with override by client when needed. I agree but when I brought the issue up, there didn't seem to be much support for making it easier... Perhaps a ticket in JIRA might garner some votes? -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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
Re: Change var in other namespace
Thanks, Sean. Exactly what I was looking for. IMO, clojure.tools.logging could of made this easier: log implementation from classpath by default with override by client when needed. On Nov 17, 11:32 pm, Sean Corfield seancorfi...@gmail.com wrote: 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
Re: Change var in other namespace
On Fri, Nov 18, 2011 at 6:35 AM, vitalyper vitaly...@yahoo.com wrote: IMO, clojure.tools.logging could of made this easier: log implementation from classpath by default with override by client when needed. I agree but when I brought the issue up, there didn't seem to be much support for making it easier... Perhaps a ticket in JIRA might garner some votes? -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. -- http://worldsingles.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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
Change var in other namespace
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
Re: Change var in other namespace
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 -- 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
Re: Change var in other namespace
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