3

I'm looking for a way to config clojure.tools.logging to output messages to nRepl. I only find some configuration to output to console.

Dzung Nguyen
  • 9,152
  • 14
  • 65
  • 104

1 Answers1

0

By default, console output printed at *nrepl-server* buffer. So if you configure clojure.tools.logging to print output to console then you can see it on *nrepl-server* buffer.

I could not find a way to change this in CIDER documentation. But I found discussion concerning this question. There is proposed such a solution:

;; run this code on the repl where you wish to see all output.
;; You will need to add the dependency [commons-io "2.4"] to your
;; leiningen dependencies.
(import 'org.apache.commons.io.output.WriterOutputStream)
(import 'java.io.PrintStream)

;; First, we redirect the raw stdout of the server to this repl
(System/setOut (PrintStream. (WriterOutputStream. *out*)
                             true)) ;; Auto-flush the PrintStream

;; Next, we alter the root binding of *out* so that new threads
;; send their output to THIS repl rather than the original System/out.
(alter-var-root #'*out* (fn [_] *out*))

;; Now the snippets should both send output to this repl:
(.println System/out "Hello stdout.")
(.start (Thread. #(println "Hello from a new thread.")))

But on my installation (CIDER 0.12.0, Clojure 1.8.0) it complains on (.start (Thread. #(println "Hello from a new thread."))):

error in process filter: [nREPL] No response handler with id nil found

However if I don't run (alter-var-root #'*out* (fn [_] *out*)) then printing examples below works good and prints its output to *cider-repl* without errors or warnings. Logger output also printed to *cider-repl*.

anton0xf
  • 51
  • 6