Why is coverage affected when using slf4j nop?

I added [org.slf4j/slf4j-nop "1.5.8"] dependency to :dev profile in project.clj to silence logs during test runs. Surprisingly it brought down the coverage (lein cloverage) by 2.5%. That was the only change made. On reverting the change the coverage increases by the same percentage. What could be the reason for this?

Guessing that Cloverage reported a change of forms but not of lines, in which case I suppose your log statements use a macro that expands to code that asks the log sink, “are you going to write this?” before bothering to compose the string, and the Nop implementation always answers “no”, so the principal branch of the expanded macro is never taken.

1 Like

Explicit log statements use timbre. And these logs are not silenced as it does not use slf4j logger. I used NOP logger to silence jetty logs.

You were right about there being no change in the number of lines. And it turns out that I am using sentry to send errors and that function happens to be a macro which logs the error before sending it out to sentry :sweat_smile:

I find the “coverage by forms” somewhat informative, yet not a clear action item. For example, if I recall correctly, (for [...] ...) expands to code that has separate branches for chunked and non-chunked sequences. Perhaps my program is of such a nature that only the chunked path will ever be followed. There is no possible way for tests to “cover” the non-chunked forms. On the other hand, if Cloverage said 100% of lines were covered but only 2% of forms, then …there might be a mystery worth solving.

1 Like