Skip to content

Commit

Permalink
Suppress some ERRORs logged by Apache Commons JCS
Browse files Browse the repository at this point in the history
  • Loading branch information
lread committed Aug 5, 2024
1 parent 5f0d9cb commit 87daa17
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* Replace deprecated clj-time dep with JDK8 java.time interop [#83](https://github.com/clj-holmes/clj-watson/issues/83)
* Improve feedback during scan
* Stop suppressing all logging [#68](https://github.com/clj-holmes/clj-watson/issues/68)
* Suppress noisy INFO level logging from Apache JCS Commons [#69](https://github.com/clj-holmes/clj-watson/issues/69)
* Suppress noisy INFO level logging from Apache Commons JCS [#69](https://github.com/clj-holmes/clj-watson/issues/69)
* Suppress specific irrelevant ERROR level logging from Apache Commons JCS [#78](https://github.com/clj-holmes/clj-watson/issues/78)

* v5.1.3 5812615 -- 2024-07-31
* Address [#60](https://github.com/clj-holmes/clj-watson/issues/60) by updating `org.owasp/dependency-check-core` to 10.0.3.
Expand Down
5 changes: 1 addition & 4 deletions resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
</encoder>
</appender>

<!-- Apache Commons JCS is very noisy at the INFO level -->
<logger name="org.apache.commons.jcs3" level="WARN" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<!-- See clj-watson.logging-config namespace for suppression of Apache Commons JCS noise -->

<root level="INFO">
<appender-ref ref="CONSOLE"/>
Expand Down
2 changes: 2 additions & 0 deletions src/clj_watson/entrypoint.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[clj-watson.controller.github.vulnerability :as controller.gh.vulnerability]
[clj-watson.controller.output :as controller.output]
[clj-watson.controller.remediate :as controller.remediate]
[clj-watson.logging-config :as logging-config]
[clojure.java.io :as io]
[clojure.tools.reader.edn :as edn]))

Expand Down Expand Up @@ -44,6 +45,7 @@
(defn do-scan
"Indirect entry point for -M usage."
[opts]
(logging-config/init)
(let [{:keys [fail-on-result output deps-edn-path]} opts
vulnerabilities (scan* opts)
contains-vulnerabilities? (->> vulnerabilities
Expand Down
43 changes: 43 additions & 0 deletions src/clj_watson/logging_config.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(ns clj-watson.logging-config
(:require [clojure.string :as str])
(:import [org.slf4j LoggerFactory]
[ch.qos.logback.classic.turbo TurboFilter]
[ch.qos.logback.classic Level LoggerContext]
[ch.qos.logback.core.spi FilterReply]))

(defn- create-custom-filter
"Suppress noise from Apache Commons JCS
- It's INFO level messages are overly noisy, only log when minimum of WARN.
- Suppress specific ERROR level messages from IndexedDiskCache that we have deemed unimportant.
These suppresssions could be achieved with Logback's EvaluatorFilter but that requires a
dependency on the Janino library. We'd like to avoid adding dependencies if possible."
[]
(proxy [TurboFilter] []
(decide [marker logger level format params throwable]
(cond (and (= Level/ERROR level)
(= "org.apache.commons.jcs3.auxiliary.disk.indexed.IndexedDiskCache"
(.getName logger))
format
(str/includes? format "Not alive and dispose was called"))
FilterReply/DENY

(and (< (.toInt level) Level/WARN_INT)
(str/starts-with? (.getName logger) "org.apache.commons.jcs3"))
FilterReply/DENY

:else
FilterReply/NEUTRAL))))

(defn init
"Complement `resources/logaback.xml` with some customizations"
[]
(.addTurboFilter (LoggerFactory/getILoggerFactory) (create-custom-filter)))

(comment
(.toInt Level/WARN)
;; => 30000
(.toInt Level/INFO)
;; => 20000

:eoc)

0 comments on commit 87daa17

Please sign in to comment.