【问题标题】:Configure clojure logging to output to nRepl配置 clojure 日志记录以输出到 nRepl
【发布时间】:2016-01-03 11:40:48
【问题描述】:

我正在寻找一种方法来配置 clojure.tools.logging 以将消息输出到 nRepl。我只找到一些配置输出到console

【问题讨论】:

    标签: logging clojure


    【解决方案1】:

    默认情况下,控制台输出打印在 *nrepl-server* 缓冲区。因此,如果您将 clojure.tools.logging 配置为将输出打印到控制台,那么您可以在 *nrepl-server* 缓冲区中看到它。

    我在 CIDER 文档中找不到更改此设置的方法。但我发现discussion 与这个问题有关。有提议这样一个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.")))
    

    但在我的安装(CIDER 0.12.0,Clojure 1.8.0)上它抱怨(.start (Thread. #(println "Hello from a new thread.")))

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

    但是,如果我不运行(alter-var-root #'*out* (fn [_] *out*)),那么下面的打印示例效果很好,并将其输出打印到 *cider-repl* 中而不会出现错误或警告。记录器输出也打印到 *cider-repl*。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 2013-09-11
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多