bhauman / figwheel-main

Figwheel Main provides tooling for developing ClojureScript applications
https://figwheel.org
Eclipse Public License 1.0
640 stars 93 forks source link

Tons of logging with tests when using Timbre and slf4j adapter #162

Open empperi opened 5 years ago

empperi commented 5 years ago

When using Figwheel Main with Leiningen in a project with Timbre and it's slf4j-adapter one gets a ton of unnecessary logging from Jetty used by Figwheel Main.

This is caused by SLF4J and how it works. SLF4J searches the classpath for implementations during classload time and picks one into use. Now since if one adds the sfl4j-adapter for Timbre into classpath it gets loaded and taken into use. Timbre on the other hand defaults to logging everything at :debug level unless otherwise specified. Timbre doesn't provide a way to give it a configuration file which it would magically load during startup (which is a good thing!) but instead opts in for declarative configuration. Now, however when executing Figwheel Main via Leiningen aliases one doesn't have a way to step in between and execute a simple Timbre initialization command to provide the logging configurations (and thus silence all Jetty logging). Also, Figwheel Main logging level configurations do not affect Jetty, it only affects Figwheel Main's own logging. Also prebuild hooks are apparently executed before actual build, not before tests or they are executed in a separate JVM instance.

The end result of all this is that when executing a simple test run with only client side test logic (no backend calls etc) this causes over 20 000 lines of logging to appear done by Jetty. As it is now I have following workarounds for this problem:

I'm currently going with the last workaround but I would want to see a real solution to this problem. And that would simply be:

Provide a prehook functionality which will be executed before Figwheel Main does anything but that it will be executed in the same JVM as where the Jetty will be. This way one can do whatever setup one needs and during that can also silence the Jetty SLF4J logger.

antonmos commented 5 years ago

prehook already exists and is working for this usecase: https://figwheel.org/config-options#pre-build-hooks

I think this can be closed.

mrrodriguez commented 4 years ago

@antonmos that is documented to run before the CLJS compilation, ie:

A collection of symbol or strings that represent Clojure functions to call just before your ClojureScript sources get built.

Saying that it solves the issue means we would need to imply that the Jetty server doesn't get started before the CLJS compilation and therefore possibly before this pre-build-hook.

This may be the case, but if so, that would be nice to be made clearer in the doc then.