3

I am trying to view sql statements that go through my application's SQL Server JDBC connector. We are using mssql-jdbc. The app uses slf4j as the logging facade and the current implementation is Logback.

According to their documentation the JDBC driver uses Java Util logging. As such I have added the bridge for SLF4J to my pom.xml file as follows:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
    </dependency>

I have also added an appender using the Microsoft documentation that looks like this:

    <logger name="com.microsoft.sqlserver.jdbc.Statement" level="FINER" additivity="false">
      <appender-ref ref="CONSOLE"/>
    </logger>

However, no logging statements are ever seen. I have tried many different ways to configure the appender. Any help is appreciated.

NOTE: These SO questions answer the generic question of redirecting a java.util logging app to logback, but it is not working for this JDBC driver:

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Dave
  • 21,524
  • 28
  • 141
  • 221

1 Answers1

0

This is an old question, but I am answering in case someone has the same issue.

You added jul-to-slf4j which is good, but you also need to configure SLF4jHandlers:

  1. Add logging.properties with the following:
handlers = org.slf4j.bridge.SLF4JBridgeHandler
  1. Load this file when your application starts. For this step, you have two choices:
  • Start your application with the java.util.logging.config.file pointing to the location of your logging.properties file. For example: java -jar -java.util.logging.config.file=/path/to/logging.properties

  • Or, load the configuration file when your application is starting:

try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/logging.properties")) {
    LogManager.getLogManager().readConfiguration(is);
} catch (IOException e) {
    // Handle error
}

And it should be good! :)

Mickael
  • 5,711
  • 2
  • 26
  • 22