babashka / babashka

Native, fast starting Clojure interpreter for scripting
https://babashka.org
Eclipse Public License 1.0
3.95k stars 244 forks source link

Wrapping built-in timbre/log! throws an error #1679

Closed publicimageltd closed 3 months ago

publicimageltd commented 3 months ago

version babashka v1.3.188

platform

linux

problem

When I bind the macro timbre/log! in a function, babashka throws an error while doing the same thing with regular clojure works.

Doing it with clojure (using deps-try com.taoensso/timbre):

user=> (require '[taoensso.timbre :as timbre])
nil
user=> (defn log-wrapper [& args] (timbre/log! :warn :p args))
#'user/log-wrapper
user=> (log-wrapper "hallo")
2024-03-11T13:17:21.548Z lenovoT14 WARN [user:1] - hallo
nil

With babashka:

user> (require '[taoensso.timbre :as timbre])
nil
user> (defn log-wrapper [& args] (timbre/log! :warn :p args))
java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol [...]
user> 

expected behavior I was expecting both to work the same way.

The backgound is that I want to bind the logging function to a dynamic variable, but timbre/log! is a macro, so I need to wrap it.

I have no idea what causes the exception.

borkdude commented 3 months ago

You can probably get around this by making log-wrapper a macro too. I'll look at the bug.

publicimageltd commented 3 months ago

I can't bind macros with binding, can I? That's what forced me initially to write a wrapper, i.e.

(binding [*some-dyn-var* timbre/info] ....

Won't compile ("Can't take the value of a macro").

But I can use println for the time being, that's ok.

publicimageltd commented 3 months ago

Thanks, I really appreciate the work you put in this!