To handle log entries created with any logging API using timber, you need to use the timber backend.
Add the following dependency (and resolver, if necessary) to your sbt build:
resolvers += "sonatype-oss-snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
libraryDependencies += "org.scalawag.timber" %% "timber-backend" % "0.7.0-SNAPSHOT"
Create a logger and log away!
import org.scalawag.timber.api._
object Main {
def main(args:Array[String]): Unit = {
val log = new Logger
log.trace("trace message")
}
}
Most dispatcher configurations won’t be as simple as the examples above. Here’s an example of a more realistic (and more complex) configuration just to give you a taste. For more detail, you should read the section on the timber DSL.
import org.scalawag.timber.api.Level._
import org.scalawag.timber.backend.dispatcher.configuration.Configuration
import org.scalawag.timber.backend.dispatcher.configuration.dsl._
val config = Configuration {
fanout (
( level >= WARN ),
( loggingClass startsWith "com.example" ) ~> ( level >= DEBUG )
) ~> file("application.log")
}
This will send any entries that have a level of WARN
or higher or were logged from a class in the com.example
package and have a level of DEBUG
or higher to the file application.log
. Any other entries will be dropped.