0
votes

I'm using Timbre for logging in Clojure. When I connect to a production instance via nREPL, I can't see the process logs unless I SSH into the machine and run journalctl.

How can I multiplex Timbre logs so that they are visible in the nREPL?

I suspect I need to alter the *out* var.

1

1 Answers

1
votes

Found an answer here: https://stackoverflow.com/a/38294275/198927

;; 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.")))