Last active
August 29, 2015 14:27
-
-
Save patrickgombert/cb3f5255b3d5921286b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol Log | |
(info [args])) | |
; We wanted to do this | |
(deftype TaggedLogger [metadata] | |
Log | |
(info [args] (apply clojure.tools.logging/info (conj metadata args)))) | |
; but info et al. are macros so we can't use apply here | |
; Then I wrote this macro in order to wrangle the problem | |
(defmacro invoke-log [level args] | |
(let [s (symbol (str "clojure.tools.logging/" level))] | |
`(~s ~@args))) | |
; so we could then do | |
(deftype TaggedLogger [metadata] | |
Log | |
(info [args] (invoke-log info (conj metadata args)))) | |
; but it emits the following log line | |
(info (TaggedLogger. "meta") (list "bar" "baz")) | |
; [2015-08-20 14:19:36,001][INFO][the-ns] (nREPL-worker-3) #<core$cons clojure.core$cons@1a4d2ef8> foo (bar baz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment