<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions and answers in tools.logging</title>
<link>https://ask.clojure.org/index.php/qa/contrib-libs/tools-logging</link>
<description></description>
<item>
<title>Answered: Using namespace as log originating class for JUL</title>
<link>https://ask.clojure.org/index.php/13427/using-namespace-as-log-originating-class-for-jul?show=13428#a13428</link>
<description>&lt;p&gt;I suspect something is wrong in your setup. I'm using Logback over SLF4J in my projects and the &lt;code&gt;logger&lt;/code&gt; key in the format always outputs the right namespace. The JUL implementation of the c.t.l logger isn't that different.&lt;/p&gt;
&lt;p&gt;Just to be absolutely certain, I created a very bare-bones project with just a single namespace:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns app.core
  (:require [clojure.tools.logging :as log]
            [clojure.tools.logging.impl :as log-impl]))

(defn -main []
  (System/setProperty &quot;java.util.logging.SimpleFormatter.format&quot;
                      &quot;[%1$tF %1$tT] [%4$-7s] [%3$s] %5$s %n&quot;)
  (binding [log/*logger-factory* (log-impl/jul-factory)]
    (log/info &quot;Hello&quot;)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It depends only on &lt;code&gt;org.clojure/tools.logging {:mvn/version &quot;1.2.4&quot;}&lt;/code&gt;.&lt;br&gt;
When it's run with &lt;code&gt;clj -M -m app.core&lt;/code&gt;, I see this in the console:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;SLF4J: Failed to load class &quot;org.slf4j.impl.StaticLoggerBinder&quot;.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[2023-11-05 16:57:41] [INFO   ] [app.core] Hello
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, the readable namespace name is there.&lt;/p&gt;
&lt;p&gt;(That was just for a quick test and you shouldn't use &lt;code&gt;c.t.l.impl&lt;/code&gt; like that of course. And probably set the format via an actual property or a properties file.)&lt;/p&gt;
</description>
<category>tools.logging</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13427/using-namespace-as-log-originating-class-for-jul?show=13428#a13428</guid>
<pubDate>Sun, 05 Nov 2023 14:59:43 +0000</pubDate>
</item>
<item>
<title>Answered: Provide slf4j 2.0 factory for tools.logging?</title>
<link>https://ask.clojure.org/index.php/12390/provide-slf4j-2-0-factory-for-tools-logging?show=12391#a12391</link>
<description>&lt;p&gt;I've created a jira to track this at &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TLOG-28&quot;&gt;https://clojure.atlassian.net/browse/TLOG-28&lt;/a&gt;. If you're interested in providing a patch, you can follow the process to become a contributor (see &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/dev/dev#_becoming_a_contributor&quot;&gt;https://clojure.org/dev/dev#_becoming_a_contributor&lt;/a&gt; ).&lt;/p&gt;
</description>
<category>tools.logging</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12390/provide-slf4j-2-0-factory-for-tools-logging?show=12391#a12391</guid>
<pubDate>Tue, 15 Nov 2022 18:23:33 +0000</pubDate>
</item>
<item>
<title>Answered: `condp = level#` in tools.logging</title>
<link>https://ask.clojure.org/index.php/10921/condp-level-in-tools-logging?show=10924#a10924</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TLOG-26&quot;&gt;https://clojure.atlassian.net/browse/TLOG-26&lt;/a&gt;&lt;/p&gt;
</description>
<category>tools.logging</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10921/condp-level-in-tools-logging?show=10924#a10924</guid>
<pubDate>Mon, 09 Aug 2021 13:23:28 +0000</pubDate>
</item>
<item>
<title>Answered: Can I suppress low-level logs with tools.logging?</title>
<link>https://ask.clojure.org/index.php/8985/can-i-suppress-low-level-logs-with-tools-logging?show=8989#a8989</link>
<description>&lt;p&gt;If you simply want to disable all logging that happens in a certain call, you can tell tools.logging to use the provided &lt;code&gt;disabled-logger-factory&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(require '[clojure.tools.logging :as log]
         '[clojure.tools.logging.impl :as log-impl])

(binding [log/*logger-factory* log-impl/disabled-logger-factory]
  (call-to-noisy-lib))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you are looking to drop messages based on the originating namespace,&lt;br&gt;
you can create your own &lt;code&gt;LoggerFactory&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def default-factory (log-impl/find-factory))

(def custom-factory
  (reify log-impl/LoggerFactory
    (name [_factory]
      &quot;some.arbitrary.name.for.this.factory&quot;)
    (get-logger [factory logger-ns]
      (if (= &quot;namespace.you.want.to.silence&quot; (str logger-ns))
        log-impl/disabled-logger
        (log-impl/get-logger default-factory logger-ns)))))

(binding [log/*logger-factory* custom-factory]
  (call-to-noisy-lib))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you addtionally want to filter based on the level of the message,&lt;br&gt;
you'll need to implement a custom logger as well.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn logger-with-levels [wrapped-logger allowed-levels]
  (reify log-impl/logger
    (enabled? [logger level]
      (when (contains? allowed-levels level)
        (log-impl/enabled? wrapped-logger level)))
    (write! [logger level throwable message]
      (when (contains? allowed-levels level)
        (log-impl/write! wrapped-logger level throwable message)))))

(def custom-factory
  (reify log-impl/LoggerFactory
    (name [_factory]
      &quot;some.arbitrary.name.for.this.factory&quot;)
    (get-logger [factory logger-ns]
      (if (= &quot;namespace.you.want.to.silence&quot; (str logger-ns))
        (logger-with-levels (log-impl/get-logger default-factory logger-ns) #{:warn})
        (log-impl/get-logger default-factory logger-ns)))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There's room for improvement, polish, and optimization here, but it looks like all the necessary pieces are available to implement the desired functionality.&lt;/p&gt;
&lt;p&gt;Personally, I'd lean towards putting this sort of thing in backend-specific configuration files, but that's explicitly not what you wanted. :) &lt;/p&gt;
</description>
<category>tools.logging</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8985/can-i-suppress-low-level-logs-with-tools-logging?show=8989#a8989</guid>
<pubDate>Sat, 04 Jan 2020 14:12:43 +0000</pubDate>
</item>
<item>
<title>Answered: Fix typo at README for `result is 1/2`</title>
<link>https://ask.clojure.org/index.php/8011/fix-typo-at-readme-for-result-is-1-2?show=8019#a8019</link>
<description>Reference: &lt;a href=&quot;https://clojure.atlassian.net/browse/TLOG-22&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://clojure.atlassian.net/browse/TLOG-22&lt;/a&gt; (reported by pfeodrippe)</description>
<category>tools.logging</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8011/fix-typo-at-readme-for-result-is-1-2?show=8019#a8019</guid>
<pubDate>Wed, 26 Jun 2019 12:00:00 +0000</pubDate>
</item>
<item>
<title>Answered: log/info removes quotes from strings making debugging harder than it needs to be.</title>
<link>https://ask.clojure.org/index.php/8010/info-removes-quotes-strings-making-debugging-harder-needs?show=8012#a8012</link>
<description>Reference: &lt;a href=&quot;https://clojure.atlassian.net/browse/TLOG-20&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://clojure.atlassian.net/browse/TLOG-20&lt;/a&gt; (reported by llsouder)</description>
<category>tools.logging</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8010/info-removes-quotes-strings-making-debugging-harder-needs?show=8012#a8012</guid>
<pubDate>Wed, 26 Jun 2019 12:00:00 +0000</pubDate>
</item>
</channel>
</rss>