Fork me on GitHub
#timbre
<
2023-12-15
>
Ho0man18:12:42

Hi everyone, When I set my timbre config to this nothing prints out except for log level :report

{:appenders
 {:stdout-1
  {:enabled? true,
   :async? true,
   :min-level :trace,
   :ns-filter #{"*"},
   :fn
   #function[taoensso.timbre.appenders.core/println-appender/fn--15539]},
  :rotor-1
  {:enabled? true,
   :async? true,
   :min-level :trace,
   :ns-filter #{"*"},
   :fn
   #function[taoensso.timbre.appenders.community.rotor/rotor-appender/fn--16864]}}}
What am I missing ? I want to config timbre in a way that :min-level and :ns-filter is set individually for each appender Thanks a lot

1
Peter Taoussanis09:12:21

Hi there! Is that your entire Timbre *config*? If so, you’ll need to add a top-level :min-level to your config that’s below any of your appender :min-levels (so :trace in your case).

(let [p (promise)]
    (with-config
      {:appenders {:my-appender {:enabled? true :fn (fn [data] (p data)) :min-level :trace}}
       :min-level :trace ; Above appender will fire iff this min-level also exists in config
      }
      (log :trace "foo"))
    (deref p 0 nil))
Basically your config needs some top-level :min-level , otherwise it currently defaults to :report. For a given log call to succeed, it’s level must meet or exceed both the top-level :min-level and the appender-specific :min-level. This is actually a little confusing (sorry about that), the default top-level :min-level should probably rather be :trace . I’ll look at adjusting that in the next release, but in the meantime you need only add the :min-level :trace to your top-level config. Does that make sense / help?

🙏 1
Ho0man10:12:33

Thanks a lot, Peter Sorry for the delay Yeah you're right I added the top level :min-level and it works now

👍 1
Ho0man10:12:41

I got another question too @UASETR481 I'm trying to use taoensso/timbre/appenders/community/rotor$rotor_appender in a project. While everything is fine in the repl when I try to run tests using lein I keep getting this error. The peculiar thing is that it may happen between two consecutive runs - one works just fine but just moments later I keep getting this :

2023-12-19T10:29:47.707Z localhost.localdomain ERROR [hermes.lib.system.components.m1.timbre:285] - ["Time Component Failed " t] => ["Time Component Failed " #error {
 :cause "taoensso.timbre.appenders.community.rotor$rotor_appender$fn__24659"
 :via
 [{:type java.lang.NoClassDefFoundError
   :message "taoensso/timbre/appenders/community/rotor$rotor_appender$fn__24659"
   :at [taoensso.timbre.appenders.community.rotor$rotor_appender invokeStatic "rotor.clj" 51]}
  {:type java.lang.ClassNotFoundException
   :message "taoensso.timbre.appenders.community.rotor$rotor_appender$fn__24659"
   :at [jdk.internal.loader.BuiltinClassLoader loadClass "BuiltinClassLoader.java" 641]}]
 :trace
 [[jdk.internal.loader.BuiltinClassLoader loadClass "BuiltinClassLoader.java" 641]
  [jdk.internal.loader.ClassLoaders$AppClassLoader loadClass "ClassLoaders.java" 188]
  [java.lang.ClassLoader loadClass "ClassLoader.java" 525]
  [taoensso.timbre.appenders.community.rotor$rotor_appender invokeStatic "rotor.clj" 51]
  [taoensso.timbre.appenders.community.rotor$rotor_appender doInvoke "rotor.clj" 51]
  [clojure.lang.RestFn invoke "RestFn.java" 408]
  [hermes.lib.system.components.m1.timbre$process_config$fn__24791$fn__24793 invoke "timbre.clj" 202]
  [clojure.core$map$fn__5931$fn__5932 invoke "core.clj" 2759]
  [clojure.lang.PersistentVector reduce "PersistentVector.java" 343]
  [clojure.core$transduce invokeStatic "core.clj" 6946]
  [clojure.core$into invokeStatic "core.clj" 6962]
  [clojure.core$into invoke "core.clj" 6950]
  [hermes.lib.system.components.m1.timbre$process_config$fn__24791 invoke "timbre.clj" 187]
  [clojure.core$update invokeStatic "core.clj" 6231]
  [clojure.core$update invoke "core.clj" 6223]
  [hermes.lib.system.components.m1.timbre$process_config invokeStatic "timbre.clj" 186]
  [hermes.lib.system.components.m1.timbre$process_config invoke "timbre.clj" 181]
  [hermes.lib.system.components.m1.timbre.Timbre-v3$fn__24857 invoke "timbre.clj" 273]
  [clojure.core.async$thread_call$fn__5905 invoke "async.clj" 486]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1136]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 635]
  [java.lang.Thread run "Thread.java" 840]]}]

Ho0man10:12:56

Here's my project.clj

Ho0man11:12:39

Sorry just one follow up. Whenever I run lein do compile :all, test (the code in question is in a test namespace) the test fails with the ClassDefNotFoundException I sent above. But if I just run the lein test everything works fine. What is special with compile :all that causes the exception? Am I getting sth worng?

Peter Taoussanis11:12:41

Clojure AOT can be non-trivial to get right - could you please explain what you’re trying to achieve exactly? Why are you running lein do compile :all, test instead of just running lein test?

Ho0man12:12:48

We try to AOT compile every artifact because it is sometimes used by Java applications in our company as well - not the timbre itself, though. The thing is the deployed jar works just fine (and we have {:aot :all} enabled) ... but the lein test after compile :all seems to fail every time. Thanks a lot for the follow-up, Peter. I think the problem is more due to my lack of knowledge regarding AOT compilation in Clojure.

Peter Taoussanis12:12:23

No problem, AOT can get tricky - and isn’t something I’m particularly familiar with myself. One common source of java.lang.NoClassDefFoundError errors I’m familiar with is when trying to run a non-uber jar without the necessary classpath setup. It’s possible that something like this is happening when you’re doing a manual compile before running your lein tests. We’d need to dig into the details of exactly what Leiningen is doing with each scenario to understand where the trouble may be - but I’m not sure the time+effort would make sense unless you have a specific motivation for wanting to do a manual compile like that first. Just running lein test should be sufficient for running your tests, unless I’m missing something unusual about your setup or needs. Hope that makes some sense?

Ho0man13:12:34

Yeah, that makes sense and I was running compile :all more out of habit than anything else. Thanks again for the help

👍 1