I am following this tutorial to set up application logging in my Clojure web app, which I am going to be using for some Datomic experimentation. The tutorial suggests that all I have to do is add Clojure's clojure.tools.logging
library to my project's dependencies in Leiningen, and output should just show up on my console. However, I am not seeing any logging output, on the console or elsewhere, when starting the app. What am I doing wrong?
Here's how I'm set up. My web stack is Ring/Compojure, running as an embedded Jetty standalone JAR (using ring.adapter.jetty
), with a dummy API route that isn't using the database yet.
My project.clj
(note: I'm evaluating Datomic's pro version, so there's GPG setup I've done outside of the project to get this protected JAR to be downloaded properly):
(defproject helloworld "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:repositories {
"my.datomic.com" {:url "https://my.datomic.com/repo" :creds :gpg}}
:dependencies [[org.clojure/clojure "1.6.0"]
[compojure "1.3.1"]
[ring/ring-defaults "0.1.2"]
[ring/ring-json "0.3.1"]
[ring/ring-defaults "0.1.2"]
[ring/ring-jetty-adapter "1.4.0"]
[org.clojure/tools.logging "0.3.1"]
[com.datomic/datomic-pro "0.9.5198" :exclusions [joda-time]]
[joda-time "2.8.1"]]
:plugins [[lein-ring "0.8.13"]]
:ring {:handler helloworld.handler/app}
:main helloworld.core
:aot [helloworld.core]
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring-mock "0.1.5"]]}})
The file src/helloworld/core.clj
:
(ns helloworld.core
(:require [clojure.tools.logging :as log]
[ring.adapter.jetty :as jetty]
[helloworld.handler :refer [app]])
(:gen-class))
(defn -main [& args]
(println "Hello, world!")
(log/info "Service is running!")
(jetty/run-jetty app {:port 8080}))
The Compojure app and API handler, src/helloworld/handler.clj
:
(ns helloworld.handler
(:require [clojure.tools.logging :as log]
[compojure.core :refer :all]
[compojure.route :as route]
[ring.middleware.defaults :refer [wrap-defaults api-defaults]]
[ring.middleware.json :as json-middleware]
[ring.util.response :refer [response]]))
(def dummy-entity {:id 1 :name "Hello, world!"})
(defroutes app-routes
(GET "/" []
(log/info "Getting all the things!")
(response [dummy-entity]))
(route/not-found "Not Found"))
(def app
(->
(wrap-defaults app-routes api-defaults)
(json-middleware/wrap-json-body)
(json-middleware/wrap-json-response)))
And here's what I see when I try to run it (this is also after hitting the default endpoint a few times):
$ lein run
Hello, world!
So println
is definitely working, but logging doesn't seem to be.