uhbif19
uhbif19

Reputation: 3245

How to find out, which backend is used for slf4j logging, in third-party library?

I am using Scala library for making HTTP requests named Bee-Client. Bee-Client, for every single action prints a lot of debugging information to console. It is using slf4j framework to do that.

My problem is to disable that logging and to redirect it into the file.

I have tried different ways to disable java.util.logging, but they all does not made any difference. Finally I realized what slf4j can use other backends, but I have no idea how to recognize it.

So I can use both logs and source code of Bee-Client. How to understand which logging backend it is using?

Upvotes: 4

Views: 3521

Answers (2)

uhbif19
uhbif19

Reputation: 3245

Another, more general way which can be used in runtime is explained here.

Upvotes: 4

yǝsʞǝla
yǝsʞǝla

Reputation: 16412

Usually by looking at transient dependencies of a dependency of interest you can figure out what logging framework it uses. In many cases it would use some sort of java logging API and would let you provide logger implementation that you like. For example look at this maven build file for your project: http://repo.bigbeeconsultants.co.uk/repo/uk/co/bigbeeconsultants/bee-client_2.10/latest/poms/bee-client_2.10.pom.

This link describes how to set Bee-Client up in your project. Basically what we can learn from SBT dependencies there:

libraryDependencies ++= Seq(
    "uk.co.bigbeeconsultants" %% "bee-client" % "0.21.+",
    "org.slf4j" % "slf4j-api" % "1.7.+",
    "ch.qos.logback" % "logback-core"    % "1.0.+",
    "ch.qos.logback" % "logback-classic" % "1.0.+"
)

resolvers += "Big Bee Consultants" at "http://repo.bigbeeconsultants.co.uk/repo"

is that it uses slf4j api and logback implementation for logging. All you need to do is to setup logback config and have dependencies listed above in your project.

For example create a config file somewhere on classpath (maybe here: src/main/resources/logback.xml). Add this contents to it and you are all set:

<configuration>

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>myApp.log</file>

    <encoder>
      <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%msg%n</pattern>
    </encoder>
  </appender>

  <root level="debug">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

See here for more details on how to configure logback.

Upvotes: 2

Related Questions