Fork me on GitHub
#cider
<
2021-09-25
>
dergutemoritz15:09:27

Heya, I'm connecting to an embedded remote REPL server (as in: nrepl.server/start-server with cider.nrepl/cider-nrepl-handler) via M-x cider-connect which works fine except for one problem: The main process is a server which writes (a lot of) log output to stderr. This all gets redirected into my REPL buffer, often grinding my Emacs instance to a halt. Is anyone aware of a way to deal with this? I could live with only having stdout redirected, for example.

vemv19:09:17

The usual thing I do is disabling stdout/stderr logging in my app by tweaking my app's Logback (or Timbre, or what have you) config I make it log to log/dev.log instead which I can tail -f if necessary (bonus tip, less +F is awesome https://www.brianstorti.com/stop-using-tail/ )

dergutemoritz11:09:36

Hey @U45T93RA6, thanks for your reply (and the nice bonus tip :D). However, logging to files is something I would prefer to avoid since that means having to take care of log rotation, compaction and purging, as well. I'd rather leave that concern to journald 😄

🍻 1
vemv11:09:40

The trick is that you only tweak logging in your dev env, where rotation is not a concern Sometimes (but not necessarily) I (File/delete "log/dev.log") on app startup, mostly so that old logs don't confuse me when debugging

dergutemoritz14:09:15

Ah yeah, I am actually talking about REPLing into a production server for purposes of doing some runtime state inspection.

vemv14:09:11

Got it So I have a snippet that should help:

(let [silently--old System/out
      silently--pw (java.io.PrintWriter. "/dev/null")
      silently--ps (java.io.PrintStream. (proxy [java.io.OutputStream] []
                                           (write
                                             ([a])
                                             ([a b c])
                                             ([a b c d e]))))]
  (binding [*out* silently--pw
            *err* silently--pw]
    (try
      (System/setOut silently--ps)
      (System/setErr silently--ps)
      ;; do your thing here...
      (finally
        (System/setOut silently--old)
        (System/setErr silently--old)))))

vemv14:09:47

the snippet is oriented for use in e.g. test suites but you can trivially adapt it for repl usage (e.g. binding -> set!)