Missing * out * in Clojure with Lein and Ring

I am running Lein 2 and cider 0.7.0. I made an example application using the ring / run berth to run.

(ns nimbus-admin.handler (:require [compojure.core :refer :all] [compojure.handler :as handler] [clojure.tools.nrepl.server :as nrepl-server] [cider.nrepl :refer (cider-nrepl-handler)] [ring.adapter.jetty :as ring] [clojure.tools.trace :refer [trace]] [ring.util.response :refer [resource-response response redirect content-type]] [compojure.route :as route]) (:gen-class)) (defroutes app-routes (GET "/blah" req "blah") (route/resources "/") (route/not-found (trace "not-found" "Not Found"))) (def app (handler/site app-routes)) (defn start-nrepl-server [] (nrepl-server/start-server :port 7888 :handler cider-nrepl-handler)) (defn start-jetty [ip port] (ring/run-jetty app {:port port :ip ip})) (defn -main ([] (-main 8080 "0.0.0.0")) ([port ip & args] (let [port (Integer. port)] (start-nrepl-server) (start-jetty ip port)))) 

then connect to it using cider, for example:

 cider-connect 127.0.0.1 7888 

I can go to my sites and eval forms in emacs and it will update the current state of my nrepl session, so this is great.

I do not see the output, either with (print "test") (println "test") (trace "out" 1)

Finally, my project file:

 (defproject nimbus-admin "0.1.0" :description "" :url "" :min-lein-version "2.0.0" :dependencies [[org.clojure/clojure "1.6.0"] [com.climate/clj-newrelic "0.1.1"] [com.ashafa/clutch "0.4.0-RC1"] [ring "1.3.1"] [clj-time "0.8.0"] [midje "1.6.3"] [org.clojure/tools.nrepl "0.2.6"] [ring/ring-json "0.3.1"] [org.clojure/tools.trace "0.7.8"] [compojure "1.1.9"] [org.clojure/data.json "0.2.5"] [org.clojure/core.async "0.1.346.0-17112a-alpha"] ] :plugins [[lein-environ "1.0.0"] [cider/cider-nrepl "0.7.0"]] :main nimbus-admin.handler) 

I run the site using lein run

Edit I can see the output ONLY when using (.println System/out msg)

+6
source share
4 answers

Have you tried (.println System/out msg) ? I had the same issue and it worked for me.

+3
source

You can simply put the print instructions in your code manually. If you want to print information about each request, you can add middleware. The handler that you pass to the pier is a function of Ring requests to Ring responses. Requesting and answering calls are just cards; see the specification ring for more keys that they must contain. Middleware is just a function that takes a handler as the first argument and returns a handler.

An example of a middleware function for printing basic information about requests and responses:

 (defn log-middleware [handler] (fn [request] (let [response (handler request)] (println "=>" (name (:request-method request)) ":" (:uri request)) (println "<=" (:status request)) response))) 

This middleware should print to the clipboard with cider, but cider behaves strangely sometimes and send output to *Messages* or to the nrepl server clipboard.

You use this middleware, applying it to your handlers:

  (def application (log-middleware (handler/site routes))) 

Headers can be printed as follows: simply enter the :headers field in the request form and print it.

+1
source

The Prone library can help you. It has ring middleware for better exception reporting, which also has debugging capabilities. When debugging, you can check any local bindings as well as the Ring request.

Here is a video demonstrating how it works

0
source

Use (flush) after your print statements to force output.

0
source

All Articles