【问题标题】:Output compojure server print statements into figwheel terminal?将 compojure 服务器打印语句输出到 figwheel 终端?
【发布时间】:2016-03-08 04:38:16
【问题描述】:

pprint/println 输出在 compojure 中的什么位置?/我可以让它显示在运行 figwheel repl 的终端窗口中吗? (对不起,如果这听起来很愚蠢,谷歌打败了我的努力)。

【问题讨论】:

  • 我自己是 Clojure 的新手,但通常 figwheel 用于前端 clojurescript,而 Compojure 用于服务器的后端 Clojure。如果我理解的话,让他们直接互动似乎有点奇怪。
  • 我认为因为lein figwheel 也启动了后端,所以它是输出服务器日志的合理位置。基本上,我正在寻找如何使用 compojure 应用程序的服务器端进行打印调试。

标签: clojure compojure


【解决方案1】:

实际上无花果有一个相关的功能会导致这种症状。您的环处理程序中的所有 print/prn 语句都将被 Figwheel 进程“吞下”,并将转到日志文件或控制台。

这是来自 project.clj 的 sn-p:

 :figwheel
  {:http-server-root "public"
   :server-port 3449
   :nrepl-port 7002
   :css-dirs ["resources/public/css"]
   :ring-handler myapp.handler/app
   :server-logfile false
   }

关键 :server-logfile 正在控制这种行为。如果它是假的,那么 out 是你的常规 repl 控制台,如果它是一个文件名,那么任何打印的东西都会去那个文件(如果它不存在,那么默认使用文件“figwheel_server.log”。

无花果轮问题: https://github.com/bhauman/lein-figwheel/issues/436 Figwheel 提交:https://github.com/bhauman/lein-figwheel/commit/330d8d7fda8be145615910cf639bd9a3242339ba

【讨论】:

    【解决方案2】:

    它似乎没有任何特殊设置就显示在那里......我在控制台上得到了这个:

    Prompt will show when Figwheel connects to your application
    "I got a request"
    

    触发处理程序:

    curl localhost:3449/foo
    

    src/with_server/server.clj

    (ns with-server.server)
    
    (defn handler [req]
      (prn "I got a request")
      {})
    

    在 project.clj 下的 :figwheel {}

    :ring-handler with-server.server/handler
    

    如果您遇到问题,也许您需要 ring-reload 中间件,以便重新加载您所做的更改?

    【讨论】:

    • 意外行为阻止了我的代码进入 prn 语句。 掌心
    猜你喜欢
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    相关资源
    最近更新 更多