There is a long and storied history behind logging on the JVM, and by extension Clojure.
The point of logging is to have some visibility into your running program. For things deployed on a thousand machines this is a harder problem than a handful of servers. All we need is a structured way of outputting text.
tools.logging
to your deps.ednThis is your "logging facade" - what you will use to emit logs.
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.12.0"}
ring/ring {:mvn/version "1.13.0"}
metosin/reitit-ring {:mvn/version "0.7.2"}
org.clojure/tools.logging {:mvn/version "1.3.0"}}
:aliases {:nREPL
{:extra-paths ["dev"]
:extra-deps
{nrepl/nrepl {:mvn/version "1.3.0"}}}
:dev {:extra-paths ["dev"]}}}
slf4j-simple
to your deps.ednThis is your "logging implementation" - the thing that determines how logs are actually emitted.
slf4j-simple
is, as the name suggests, the simplest possible implementation. It outputs
all logs to standard error. If that is not enough for you then you can pick something else.
Once you add this you should notice that you no longer get warnings when you start up. In addition, you will start to see logs from the underlying server libraries.
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.12.0"}
ring/ring {:mvn/version "1.13.0"}
metosin/reitit-ring {:mvn/version "0.7.2"}
org.clojure/tools.logging {:mvn/version "1.3.0"}
org.slf4j/slf4j-simple {:mvn/version "2.0.16"}}
:aliases {:nREPL
{:extra-paths ["dev"]
:extra-deps
{nrepl/nrepl {:mvn/version "1.3.0"}}}
:dev {:extra-paths ["dev"]}}}
Since the server doesn't do much yet, emitting a log for each request that comes in is a decent enough start.
(ns example.routes
(:require [reitit.ring :as reitit-ring]
[clojure.tools.logging :as log]))
...
(defn root-handler
[system request]
(log/info (str (:request-method request) " - " (:uri request)))
(let [handler (reitit-ring/ring-handler
(reitit-ring/router
(routes system))
#'not-found-handler)]
(handler request)))