【问题标题】:How to see Timbre logs via nREPL?如何通过 nREPL 查看音色日志?
【发布时间】:2020-09-25 13:42:51
【问题描述】:

我正在使用Timbre 登录 Clojure。当我通过 nREPL 连接到生产实例时,除非我通过 SSH 连接到机器并运行 journalctl,否则我看不到进程日志。

如何多路复用音色日志,以便它们在 nREPL 中可见?

我怀疑我需要更改 *out* 变量。

【问题讨论】:

    标签: logging clojure nrepl timbre


    【解决方案1】:

    在这里找到答案: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.")))
    

    【讨论】:

      猜你喜欢
      • 2020-09-12
      • 2010-09-07
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      • 2021-04-06
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      相关资源
      最近更新 更多