我正在使用Timbre登录 Clojure。当我通过 nREPL 连接到生产实例时,除非我通过 SSH 连接到机器并运行journalctl
.
如何多路复用音色日志,以便它们在 nREPL 中可见?
我怀疑我需要更改*out*
var。
在这里找到了答案: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.")))