I really like the clojure.contrib.logging library, but I find myself
often getting tricked into thinking it works like println:

    (info "Doing a thing with a vector: " my-vec)

or

    (catch Exception e
      (warn "Problem doing a thing with: " my-vec e))

Attached is a patch altering the logging library to behave this way by
accepting var-args and treating the last one as a throwable if applicable.

What do you think? Do other people have the same problem I do?

-Phil

-- 
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
From: Jim <j...@jim-laptop.(none)>
Date: Mon, 11 Jan 2010 16:32:12 -0600
Subject: [PATCH] Change logging macros to apply str to message args.

---
 src/clojure/contrib/logging.clj |   70 ++++++++++++++++-----------------------
 1 files changed, 29 insertions(+), 41 deletions(-)

diff --git a/src/clojure/contrib/logging.clj b/src/clojure/contrib/logging.clj
index 97bbfcf..1ca5189 100644
--- a/src/clojure/contrib/logging.clj
+++ b/src/clojure/contrib/logging.clj
@@ -306,44 +306,32 @@
                        (log-stream :error ~log-ns))]
       ~...@body)))
 
-(defmacro trace
-  "Logs a message at the trace level."
-  ([message]
-    `(log :trace ~message))
-  ([message throwable]
-    `(log :trace ~message ~throwable)))
-
-(defmacro debug
-  "Logs a message at the debug level."
-  ([message]
-    `(log :debug ~message))
-  ([message throwable]
-    `(log :debug ~message ~throwable)))
-
-(defmacro info
-  "Logs a message at the info level."
-  ([message]
-    `(log :info ~message))
-  ([message throwable]
-    `(log :info ~message ~throwable)))
-
-(defmacro warn
-  "Logs a message at the warn level."
-  ([message]
-    `(log :warn ~message))
-  ([message throwable]
-    `(log :warn ~message ~throwable)))
-
-(defmacro error
-  "Logs a message at the error level."
-  ([message]
-    `(log :error ~message))
-  ([message throwable]
-    `(log :error ~message ~throwable)))
-
-(defmacro fatal
-  "Logs a message at the fatal level."
-  ([message]
-    `(log :fatal ~message))
-  ([message throwable]
-    `(log :fatal ~message ~throwable)))
+(defmacro trace [& args]
+  `(if (instance? Throwable ~(last args))
+     (log :trace (str ~@(butlast args)) ~(last args))
+     (log :trace (str ~...@args))))
+
+(defmacro debug [& args]
+  `(if (instance? Throwable ~(last args))
+     (log :debug (str ~@(butlast args)) ~(last args))
+     (log :debug (str ~...@args))))
+
+(defmacro info [& args]
+  `(if (instance? Throwable ~(last args))
+     (log :info (str ~@(butlast args)) ~(last args))
+     (log :info (str ~...@args))))
+
+(defmacro warn [& args]
+  `(if (instance? Throwable ~(last args))
+     (log :warn (str ~@(butlast args)) ~(last args))
+     (log :warn (str ~...@args))))
+
+(defmacro error [& args]
+  `(if (instance? Throwable ~(last args))
+     (log :error (str ~@(butlast args)) ~(last args))
+     (log :error (str ~...@args))))
+
+(defmacro fatal [& args]
+  `(if (instance? Throwable ~(last args))
+     (log :fatal (str ~@(butlast args)) ~(last args))
+     (log :fatal (str ~...@args))))
-- 
1.6.3.3

Reply via email to