New release! https://clojurians.slack.com/archives/C06MAR553/p1756995848476369
I'm reading logging impl in BB - I want to use clojure.tools.logging but create my own appender, if I understand correctly - it's a matter of creating my own LoggerFactory, like here?: https://github.com/babashka/babashka/blob/4f2a8aafbf93cfc925c77a426ac1d5f4029387b6/feature-logging/babashka/impl/logging.clj#L278-L287
I want to use JSON as logging format, to make BB emit logs in same way as our JVM apps do
It's easier to do this via timbre which is the default logger and plugged into clojure.tools.logging. Let me find some snippets for you
ah it's from a thread you asked before :) https://clojurians.slack.com/archives/CLX41ASCS/p1747678325976339?thread_ts=1747671299.406549&cid=CLX41ASCS
dang, I knew I was researching this before and lost track of it facepalm
thank you, as always
indeed :-)
Problem after upgrading to .208:
Has something changed with data-readers in particular, or Vars in general?
I set up a custom reader:
(set! *data-readers* (assoc *data-readers* 'nu/instant inst))
And, later, in a namespace that sends requests:
#(edn/read-string {:readers *data-readers*} %)
This worked fine in 1.12.207, but the data-readers has reverted in the second case. Also, tests that read a file with the #nu/instant tag fail for the same reason. I also tried alter-var-root and am getting the same behavior.
Yes, something has changed, load-string now binds *data-readers* similar to Compiler/load but this might have introduced a bug. Can you verify if the behavior is different in Clojure and file an issue?
I'll take a look at this first thing in the morning
> And, later, in a namespace that sends requests: Is that in the same namespace or a different one?
Also, this is now failing in BB but not Clojure:
(->> "nucli/commands/managed_deps/pulls-response.edn"
io/resource
slurp
(edn/read-string {:readers readers/nu-readers}))
fails with:
ERROR in nucli.commands.managed-deps.repo-test/repo-activity (parser.cljc:555)
Uncaught exception, not in assertion.
Exception: java.lang.Exception: No reader function for tag nu/instant
at edamame.impl.parser$parse_sharp.invokeStatic (parser.cljc:555)
edamame.impl.parser$dispatch.invokeStatic (parser.cljc:638)
edamame.impl.parser$parse_next.invokeStatic (parser.cljc:769)
edamame.impl.parser$parse_next.invoke (parser.cljc:757)
edamame.impl.parser$parse_next.invokeStatic (parser.cljc:758)
edamame.impl.parser$parse_next.invoke (parser.cljc:757)
edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:248)
edamame.impl.parser$parse_to_delimiter.invoke (parser.cljc:235)
edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:237)
edamame.impl.parser$parse_map.invokeStatic (parser.cljc:574)
edamame.impl.parser$dispatch.invokeStatic (parser.cljc:672)
edamame.impl.parser$parse_next.invokeStatic (parser.cljc:769)
edamame.impl.parser$parse_next.invoke (parser.cljc:757)
edamame.impl.parser$parse_next.invokeStatic (parser.cljc:758)
edamame.impl.parser$parse_next.invoke (parser.cljc:757)
edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:248)
edamame.impl.parser$parse_to_delimiter.invoke (parser.cljc:235)
edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:237)
edamame.impl.parser$parse_map.invokeStatic (parser.cljc:574)
edamame.impl.parser$dispatch.invokeStatic (parser.cljc:672)
edamame.impl.parser$parse_next.invokeStatic (parser.cljc:769)
edamame.impl.parser$parse_next.invoke (parser.cljc:757)
edamame.impl.parser$parse_next.invokeStatic (parser.cljc:758)
edamame.impl.parser$parse_next.invoke (parser.cljc:757)
edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:248)
edamame.impl.parser$parse_to_delimiter.invoke (parser.cljc:235)
edamame.impl.parser$parse_to_delimiter.invokeStatic (parser.cljc:237)
edamame.impl.parser$parse_map.invokeStatic (parser.cljc:574)
edamame.impl.parser$dispatch.invokeStatic (parser.cljc:672)
edamame.impl.parser$parse_next.invokeStatic (parser.cljc:769)
edamame.impl.parser$parse_next.invoke (parser.cljc:757)
edamame.impl.parser$parse_next.invokeStatic (parser.cljc:758)
edamame.core$parse_next.invokeStatic (core.cljc:126)
sci.impl.parser$parse_next$fn__3133.invoke (parser.cljc:166)
sci.impl.parser$parse_next.invokeStatic (parser.cljc:166)
So problem #1 is related to *data-readers* value reverting after the call to set!.
Problem #2 seems to be clojure.edn/read-string ignoring the :readers option.
is that a new problem or was it already in bb?
In .207 all I needed was the set! of *data-readers* and that code was using clojure.core/read-string not clojure.edn/read-string.
can you make an isolated repro to avoid confusion?
Yes, let me put something together.
I'm not sure if the example earlier intended to be read-string or edn/read-string. edn/read-string should not print anything related to edamame
Here's a little test case:
borkdude@MBP25-2 ~/dev/scratch/data_reader $ cat src/foo.clj
(ns foo)
(set! *data-readers* (assoc *data-readers* 'foo/bar identity))
(require 'bar)
(defn exec [_]
(prn bar/x))
borkdude@MBP25-2 ~/dev/scratch/data_reader $ cat src/bar.clj
(ns bar)
(def x #foo/bar [1 2 3])
borkdude@MBP25-2 ~/dev/scratch/data_reader $ clj -X foo/exec
[1 2 3]
borkdude@MBP25-2 ~/dev/scratch/data_reader $ bb -cp src -x foo/exec
[1 2 3]
How is your test case different?and this fails in both clj + bb:
(ns foo
(:require [clojure.edn :as edn]))
(set! *data-readers* (assoc *data-readers* 'foo/bar identity))
(require 'bar)
(defn exec [_]
(prn bar/x)
(prn *data-readers*)
(prn (edn/read-string {:readers *data-readers*} "#foo/bar [1 2 3]")))
(added the edn/read-string call.
This is because *data-readers* is no longer bound to the value you set at the top level. It's re-bound to the original, same behavior as ClojureThis does work in both clj + bb:
(prn (edn/read-string {:readers (assoc *data-readers* 'foo/bar identity)} "#foo/bar [1 2 3]"))So, possibly my code was invalid but still worked in .207. Just about have a test case for you, but nothing new compared to your notes above.
Yes, this was "fixed" in bb to align more with JVM Clojure
Ok. I'm only about 15 years into Clojure, I'm sure I'll figure out how Vars get bound in a REPL soon. 😞
the issue that was previously there was that in threads, *data-readers* would not be bound correctly in a future:
(prn @(future (load-string "*data-readers*")))
This would fail. Actually the example I encountered before was *warn-on-reflection* but same problem.If you still have something that isn't conform clojure with respect to Vars, happy to hear it.
Ok, I was totally panicing on the edn/read-string part. Turns out I had a second test using read-string that also needed to switch to edn/read-string.
Glad we sorted it out 😅
and sorry for the inconvenience
Nah, this was all me. Thanks for helping me sort it out.