配置 clojure 日志记录以输出到 nRepl

问题描述 投票:0回答:2

我正在寻找一种配置

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

logging clojure
2个回答
0
投票

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

我在 CIDER 文档中找不到更改此设置的方法。但我发现关于这个问题的discussion。提出了这样一个解决方案

;; 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*。


0
投票

cider-log-appender 对我有用。我使用了 logback。

© www.soinside.com 2019 - 2024. All rights reserved.