I’m trying to figure out how to reduce the logging level during test runs and having trouble making heads or tails of the documentation on how to do this. I confess I’m not super seasoned with Java and the world of SLF4J looks like a labrinth I’d love to avoid going deep into if possible. I’ve looked at the https://pedestal.io/pedestal/0.7/reference/logging.html and the https://pedestal.io/api/0.7/io.pedestal.log.html. The more I read them the more condused I get. I also saw a https://shivekkhurana.medium.com/learn-clojure-by-building-a-drug-dealer-api-part-2-de8c47512a71 but surely there is a way to do it in code? When I run tests (basically doing as in the https://pedestal.io/pedestal/0.8/guides/unit-testing.html) via the command line/test runner I get info messages spewed all over the console. (At the repl I solved this by redirecting err but my clojure test runner seems to grab stderr back and pipes it to the console) Thanks for any pointers - even just the fn/approach I should be investigating
If you used the pedestal template for create your project, you should have file test-resources/logback-test.xml which is the logging configuration that will be used with the :test alias. You can verify this by checking if your deps.edn file includes the test-resources directory in the extra-paths.
when logback configures itself, it looks for a file logback-test.xml in the resources before it looks for logback.xml and it will use the test file's config in preference to the other. Putting that file in a resource directory that is only included for testing profiles is encouraged by the logback library.
to be fair, https://digitalbuff.dev/articles/technology/java-logging-libraries of one library after another of trying to subsume and improve one another. Until you've wrestled with this particular beast at least once, it's confusing as hell. Good luck!
an answer your question: you can absolutely https://github.com/qos-ch/logback/tree/master/logback-examples/src/main/java/chapters/configuration, but I find it simpler with XML files, unpleasant though XML is...
and in case you do go with the XML file config, you might find lines like these useful:
<logger name="cognitect.aws" level="warn"/>
<logger name="org.apache.zookeeper" level="warn"/>
<logger name="org.apache.curator" level="warn"/>the java packages/clojure namespaces that match the value in the name tag and all children of them will only log messages at level WARN or above.
Thank you! I did not use the template, I used the Getting Started in the docs as a guide and followed those steps to learn it, then split off when I needed to do my actual project with the same sort of setup. BUT that’s a great pointer and i’ll see how it is set up and copy over what I need. I am fine to do some XML editing if needed, as long as I know it’s the best way! I appreciate the pointers! 🙏
Not sure it’s the gold standard or the best way. There are lots of good ways. Hope you find one that works for you. 😊
thanks! i was using SL4J but basically just cargo culted it over from probably whatever i saw first in the docs or Getting Started to make things work. judging from the template, I should swap in logback dep for the SL4J dep to make this work, which should be fine. i’m pretty agnostic on what i use until i hit some sort of logging need that can’t be covered. The very little i’ve done with logging explicitly has been using some of the generic logging stuff in pedestal which should work with a different adapter - or i’ll find out if that’s the case at least lol
Test issue fixed, thanks to the magic of XML (2003 was great)! Thanks for your help @sirwobin