Output compojure server print statements into figwheel terminal?

99封情书 提交于 2019-12-23 04:57:13

问题


Where does pprint/println output go in compojure?/Can I get it to show up in the terminal window that the figwheel repl is running in? (Sorry if this sounds dumb, google bested my efforts).


回答1:


Actually Figwheel has a related feature to cause such symptoms. All print/prn statements in your ring handlers will be "swallowed" by the Figwheel process and will either go to a log file or to the console.

Here is a snippet from project.clj:

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

The key :server-logfile is controlling this behavior. If it's false, then out is your regular repl console, if it's a filename, then anything printed will go to that file (if it's not present, then the default is using file "figwheel_server.log".

Figwheel issue: https://github.com/bhauman/lein-figwheel/issues/436 Figwheel commit: https://github.com/bhauman/lein-figwheel/commit/330d8d7fda8be145615910cf639bd9a3242339ba




回答2:


It seems to show up there without any special setup... I get this at the console:

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

Triggering the handler:

curl localhost:3449/foo

src/with_server/server.clj

(ns with-server.server)

(defn handler [req]
  (prn "I got a request")
  {})

In project.clj under :figwheel {}

:ring-handler with-server.server/handler

If you are having trouble, maybe you need ring-reload middleware so that the changes you are making get reloaded?



来源:https://stackoverflow.com/questions/35859079/output-compojure-server-print-statements-into-figwheel-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!