Permalink
Browse files

Fix broken protocol extension due to incompatibility between syntax-q…

…uote and extend-type. Add tests for all provided implementations.
  • Loading branch information...
1 parent 0f347ac commit f9cb0a7232d3a11cb7e74e4c13c3adc054e7e7a2 Alexander Taggart committed Sep 29, 2011
View
@@ -44,12 +44,12 @@ Logging is available in Maven central. Add it to your Maven project's `pom.xml`
<dependency>
<groupId>org.clojure</groupId>
<artifactId>tools.logging</artifactId>
- <version>0.2.2</version>
+ <version>0.2.0</version>
</dependency>
or your leiningen project.clj:
- [org.clojure/tools.logging "0.2.2"]
+ [org.clojure/tools.logging "0.2.0"]
Please note the changelog below.
View
27 pom.xml
@@ -21,4 +21,31 @@
<developerConnection>scm:git:git@github.com:clojure/tools.logging.git</developerConnection>
<url>git@github.com:clojure/tools.logging.git</url>
</scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.6.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
@@ -40,27 +40,29 @@
(Class/forName "org.slf4j.Logger")
(eval
`(do
- (extend-type org.slf4j.Logger
+ (extend org.slf4j.Logger
Logger
- (enabled? [logger# level#]
- (condp = level#
- :trace (.isTraceEnabled logger#)
- :debug (.isDebugEnabled logger#)
- :info (.isInfoEnabled logger#)
- :warn (.isWarnEnabled logger#)
- :error (.isErrorEnabled logger#)
- :fatal (.isErrorEnabled logger#)
- (throw (IllegalArgumentException. (str level#)))))
- (write! [^org.slf4j.Logger logger# level# ^Throwable e# msg#]
- (let [^String msg# (str msg#)]
- (condp = level#
- :trace (.trace logger# msg# e#)
- :debug (.debug logger# msg# e#)
- :info (.info logger# msg# e#)
- :warn (.warn logger# msg# e#)
- :error (.error logger# msg# e#)
- :fatal (.error logger# msg# e#)
- (throw (IllegalArgumentException. (str level#)))))))
+ {:enabled?
+ (fn [logger# level#]
+ (condp = level#
+ :trace (.isTraceEnabled logger#)
+ :debug (.isDebugEnabled logger#)
+ :info (.isInfoEnabled logger#)
+ :warn (.isWarnEnabled logger#)
+ :error (.isErrorEnabled logger#)
+ :fatal (.isErrorEnabled logger#)
+ (throw (IllegalArgumentException. (str level#)))))
+ :write!
+ (fn [^org.slf4j.Logger logger# level# ^Throwable e# msg#]
+ (let [^String msg# (str msg#)]
+ (condp = level#
+ :trace (.trace logger# msg# e#)
+ :debug (.debug logger# msg# e#)
+ :info (.info logger# msg# e#)
+ :warn (.warn logger# msg# e#)
+ :error (.error logger# msg# e#)
+ :fatal (.error logger# msg# e#)
+ (throw (IllegalArgumentException. (str level#))))))})
(reify LoggerFactory
(name [_#]
"org.slf4j")
@@ -76,26 +78,28 @@
(Class/forName "org.apache.commons.logging.Log")
(eval
`(do
- (extend-type org.apache.commons.logging.Log
+ (extend org.apache.commons.logging.Log
Logger
- (enabled? [logger# level#]
- (condp = level#
- :trace (.isTraceEnabled logger#)
- :debug (.isDebugEnabled logger#)
- :info (.isInfoEnabled logger#)
- :warn (.isWarnEnabled logger#)
- :error (.isErrorEnabled logger#)
- :fatal (.isFatalEnabled logger#)
- (throw (IllegalArgumentException. (str level#)))))
- (write! [logger# level# e# msg#]
- (condp = level#
- :trace (.trace logger# msg# e#)
- :debug (.debug logger# msg# e#)
- :info (.info logger# msg# e#)
- :warn (.warn logger# msg# e#)
- :error (.error logger# msg# e#)
- :fatal (.fatal logger# msg# e#)
- (throw (IllegalArgumentException. (str level#))))))
+ {:enabled?
+ (fn [logger# level#]
+ (condp = level#
+ :trace (.isTraceEnabled logger#)
+ :debug (.isDebugEnabled logger#)
+ :info (.isInfoEnabled logger#)
+ :warn (.isWarnEnabled logger#)
+ :error (.isErrorEnabled logger#)
+ :fatal (.isFatalEnabled logger#)
+ (throw (IllegalArgumentException. (str level#)))))
+ :write!
+ (fn [logger# level# e# msg#]
+ (condp = level#
+ :trace (.trace logger# msg# e#)
+ :debug (.debug logger# msg# e#)
+ :info (.info logger# msg# e#)
+ :warn (.warn logger# msg# e#)
+ :error (.error logger# msg# e#)
+ :fatal (.fatal logger# msg# e#)
+ (throw (IllegalArgumentException. (str level#)))))})
(reify LoggerFactory
(name [_#]
"org.apache.commons.logging")
@@ -116,20 +120,22 @@
:warn org.apache.log4j.Level/WARN
:error org.apache.log4j.Level/ERROR
:fatal org.apache.log4j.Level/FATAL}]
- (extend-type org.apache.log4j.Logger
+ (extend org.apache.log4j.Logger
Logger
- (enabled? [logger# level#]
- (.isEnabledFor logger#
- (or
- (levels# level#)
- (throw (IllegalArgumentException. (str level#))))))
- (write! [logger# level# e# msg#]
- (let [level# (or
- (levels# level#)
- (throw (IllegalArgumentException. (str level#))))]
- (if-not e#
- (.log logger# level# msg#)
- (.log logger# level# msg# e#)))))
+ {:enabled?
+ (fn [logger# level#]
+ (.isEnabledFor logger#
+ (or
+ (levels# level#)
+ (throw (IllegalArgumentException. (str level#))))))
+ :write!
+ (fn [logger# level# e# msg#]
+ (let [level# (or
+ (levels# level#)
+ (throw (IllegalArgumentException. (str level#))))]
+ (if-not e#
+ (.log logger# level# msg#)
+ (.log logger# level# msg# e#))))})
(reify LoggerFactory
(name [_#]
"org.apache.log4j")
@@ -150,22 +156,24 @@
:warn java.util.logging.Level/WARNING
:error java.util.logging.Level/SEVERE
:fatal java.util.logging.Level/SEVERE}]
- (extend-type java.util.logging.Logger
+ (extend java.util.logging.Logger
Logger
- (enabled? [logger# level#]
- (.isLoggable logger#
- (or
- (levels# level#)
- (throw (IllegalArgumentException. (str level#))))))
- (write! [logger# level# ^Throwable e# msg#]
- (let [^java.util.logging.Level level#
- (or
- (levels# level#)
- (throw (IllegalArgumentException. (str level#))))
- ^String msg# (str msg#)]
- (if e#
- (.log logger# level# msg# e#)
- (.log logger# level# msg#)))))
+ {:enabled?
+ (fn [logger# level#]
+ (.isLoggable logger#
+ (or
+ (levels# level#)
+ (throw (IllegalArgumentException. (str level#))))))
+ :write!
+ (fn [logger# level# ^Throwable e# msg#]
+ (let [^java.util.logging.Level level#
+ (or
+ (levels# level#)
+ (throw (IllegalArgumentException. (str level#))))
+ ^String msg# (str msg#)]
+ (if e#
+ (.log logger# level# msg# e#)
+ (.log logger# level# msg#))))})
(reify LoggerFactory
(name [_#]
"java.util.logging")
@@ -3,6 +3,15 @@
clojure.tools.logging]
[:require [clojure.tools.logging.impl :as impl]])
+(deftest test-impls
+ (are [lf] (binding [*logger-factory* lf]
+ (enabled? :fatal))
+ (impl/slf4j-factory)
+ (impl/cl-factory)
+ (impl/log4j-factory)
+ (impl/jul-factory)))
+
+
(def ^{:dynamic true} *entries* (atom []))
(defn test-factory [enabled-set]
@@ -0,0 +1,4 @@
+log4j.rootLogger=TRACE, A1
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d %-5p %c: %m%n

0 comments on commit f9cb0a7

Please sign in to comment.