0

When I am testing my class, application writes lots of stuff to the console, because of logging (I am using SLF4J). How do I disable logging in this case, without introducing special flag inside tested class?

1 Answer 1

1

SLF4J is only a facade, meaning that it does not provide a complete logging solution, so if you are using it with LOG4J just change your logging level to OFF. For more info see https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html#OFF

So you can have two log4j.xml configuration files, one for production and one for testing with logging level set to OFF or better to WARN.

1
  • Which, in turn, means, that my tests become implementation-dependent. Or I should introduce something like TestLoggerManager with static methods in it. Commented Jun 3, 2014 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.