How to find which library slf4j has bound itself to?

Just do what SLF4J does to discover the binding: final StaticLoggerBinder binder = StaticLoggerBinder.getSingleton(); Now you can try to find out what is the actual implementation logback in my case: System.out.println(binder.getLoggerFactory()); System.out.println(binder.getLoggerFactoryClassStr()); This prints: ch.qos.logback.classic.LoggerContext[default] ch.qos.logback.classic.selector.DefaultContextSelector

How can I get complete stacktraces for exceptions thrown in tests when using sbt and testng?

Using hints found in the documentation here: (quoted) You can configure the output shown when running with sbt in four ways: 1) turn off color, 2) show short stack traces, 3) full stack traces, and 4) show durations for everything. To do so you must pass a -o argument to ScalaTest, and after the -o, … Read more

How to enable debug in slf4j Logger?

Programmatically, with logback: setLoggingLevel(ch.qos.logback.classic.Level.DEBUG); where public static void setLoggingLevel(ch.qos.logback.classic.Level level) { ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); root.setLevel(level); }

Mocking Logger and LoggerFactory with PowerMock and Mockito

EDIT 2020-09-21: Since 3.4.0, Mockito supports mocking static methods, API is still incubating and is likely to change, in particular around stubbing and verification. It requires the mockito-inline artifact. And you don’t need to prepare the test or use any specific runner. All you need to do is : @Test public void name() { try … Read more

What is the best way to unit-test SLF4J log messages?

Create a test rule: import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; import org.slf4j.LoggerFactory; import java.util.List; import java.util.stream.Collectors; public class LoggerRule implements TestRule { private final ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); private final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); @Override public Statement apply(Statement base, Description description) { return new Statement() { @Override … Read more

JUL to SLF4J Bridge

You need to call SLF4JBridgeHandler.install(). You also need to enable all log levels at the root logger (reason in excerpt below) in java.util.logging and remove the default console appender. This handler will redirect jul logging to SLF4J. However, only logs enabled in j.u.l. will be redirected. For example, if a log statement invoking a j.u.l. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)