Fork me on GitHub
#nrepl
<
2023-05-09
>
Steven Lombardi19:05:20

Not sure if this is an nrepl thing or a cider thing. I think it's a cider-nrepl thing. I start my repl using the following incantation:

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"1.0.0"},cider/cider-nrepl {:mvn/version,"0.28.5"}}}' -M:dev:test -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"
Logs that occur synchronously (same thread as the repl) go to the repl window. Logs from all other threads go to the console where I ran that command. I'd like to be able to route all logging to one or the other as I desire, but I can't find the settings to do this kind of toggle, or the binding I need to override. I found this: https://docs.cider.mx/cider-nrepl/nrepl-api/ops.html#out-unsubscribe but I'm not sure how to use it.

👀 4
ag19:05:45

maybe check cider-redirect-server-output-to-repl var?

Steven Lombardi20:05:29

I can't find that var in the cider-nrepl repo. Or in the nrepl repo. I'm not using emacs so I don't think cider itself is in play here. I'm using Calva.

Ivar Refsdal17:05:01

There is an issue (and gist "fix") for this: https://github.com/nrepl/nrepl/issues/119

🙏 4
❤️ 2
👀 2
Steven Lombardi21:08:16

Sorry I'm incredibly late to respond. Yeah this helps a little bit but it doesn't let me redirect *out* to System/out which is what I need. And it appears this doesn't work:

(alter-var-root #'*out* (fn [_] (java.io.PrintWriter. System/out)))

Steven Lombardi21:08:11

I think something else is writing bindings on top of *out* so my var altering is ignored. But I'm not sure where.

Steven Lombardi21:08:07

Since this thread is pretty old / stale I think I'm going to open up a new one and watch it a bit more closely this time.

Steven Lombardi21:08:16

Solved my issue, ironically around the time @pez is asking related questions, so I'll send this back to the channel. If I set a binding when I start the system, I can get the behavior I'm looking for: all logs go to the nREPL server out not client out.

(binding [*out* (java.io.PrintWriter. System/out)
            *err* (java.io.PrintWriter. System/err)]
    (def test-system (component/start (new-test-system default-test-config))))
If at any point I want to shift output to the client, I can restart the system and use the aforementioned gist.

pez06:08:44

Thanks for sharing this, @U02GSTHEX3M! 🙏

🎉 2
Steven Lombardi21:08:16

Solved my issue, ironically around the time @pez is asking related questions, so I'll send this back to the channel. If I set a binding when I start the system, I can get the behavior I'm looking for: all logs go to the nREPL server out not client out.

(binding [*out* (java.io.PrintWriter. System/out)
            *err* (java.io.PrintWriter. System/err)]
    (def test-system (component/start (new-test-system default-test-config))))
If at any point I want to shift output to the client, I can restart the system and use the aforementioned gist.