Skip to content

Commit f0b7aeb

Browse files
committed
Setup logging
This silences Jetty logging, which can be otherwise noisy, especially when using the `:port 0` option.
1 parent 777f5c9 commit f0b7aeb

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

project.clj

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
:url "http://www.opensource.org/licenses/mit-license.php"}
66
:dependencies [[org.clojure/clojure "1.8.0"]
77
[slingshot "0.12.2"]]
8-
:profiles {:test {:dependencies [[ring/ring-jetty-adapter "1.3.2"]]}
8+
:profiles {:test {:dependencies [[ring/ring-jetty-adapter "1.3.2"]
9+
[ch.qos.logback/logback-classic "1.2.3"
10+
:exclusions [org.slf4j/slf4j-api]]
11+
[org.slf4j/jcl-over-slf4j "1.7.26"]
12+
[org.slf4j/jul-to-slf4j "1.7.26"]
13+
[org.slf4j/log4j-over-slf4j "1.7.26"]]
14+
:resource-paths ["test-resources"]}
915
:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
1016
:1.5 {:dependencies [[org.clojure/clojure "1.5.0"]]}
1117
:1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]}

test-resources/logback.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{ISO8601,Europe/London} [%thread] %-5level %logger{36} - %msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
9+
<root level="INFO">
10+
<appender-ref ref="STDOUT"/>
11+
</root>
12+
13+
<logger name="org.eclipse.jetty.server" level="ERROR"/>
14+
<logger name="org.eclipse.jetty.util.log" level="ERROR"/>
15+
<logger name="org.eclipse.jetty.util.ssl" level="ERROR"/>
16+
<logger name="org.eclipse.jetty.util.component" level="ERROR"/>
17+
</configuration>

test/setup.clj

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(ns setup
2+
"This namespace will be automaticaly loaded by the test runner"
3+
(:require
4+
[clojure.string :as string])
5+
(:import
6+
(org.eclipse.jetty.util MultiException)))
7+
8+
(-> (reify Thread$UncaughtExceptionHandler
9+
(uncaughtException [_ thread e]
10+
;; Omit exceptions coming from "Address already in use" because they're meaningless
11+
;; (these happen when one picks port 0, and after one such exception a new port will be retried successfully)
12+
(let [omit? (and (instance? MultiException e)
13+
(->> ^MultiException e
14+
.getThrowables
15+
(every? (fn [^Throwable t]
16+
(-> t .getMessage (string/includes? "Address already in use"))))))]
17+
(when-not omit?
18+
(-> ^Throwable e .printStackTrace)
19+
(when (System/getenv "CI")
20+
(System/exit 1))))))
21+
22+
(Thread/setDefaultUncaughtExceptionHandler))

0 commit comments

Comments
 (0)