Logback with Logstash

The recommended option for Logback is to use blindsight-logstash.

Structured Logging is provided through the DSL on the logger and provides a mapping for Argument and Markers through Logstash Markers and StructuredArguments. Source information (line, file, enclosing) is rendered as logstash markers.

Add the following resolver:

resolvers += Resolver.bintrayRepo("tersesystems", "maven")

And then add the given dependencies:

sbt
libraryDependencies += "com.tersesystems.blindsight" %% "blindsight-logstash" % "1.4.0-RC4"
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependency>
  <groupId>com.tersesystems.blindsight</groupId>
  <artifactId>blindsight-logstash_${scala.binary.version}</artifactId>
  <version>1.4.0-RC4</version>
</dependency>
Gradle
versions += [
  ScalaBinary: "2.13"
]
dependencies {
  compile group: 'com.tersesystems.blindsight', name: "blindsight-logstash_${versions.ScalaBinary}", version: '1.4.0-RC4'
}

See Github for the latest version.

The version of logstash-logback-encoder depends on Jackson 2.11, which is newer than the packaged version used by many Scala libraries such as Play and Akka which depend on an older version of jackson-module-scala. If you see library incompatibility errors, add an explicit dependency on 2.11 to your project:

sbt
libraryDependencies += "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.11.0"
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependency>
  <groupId>com.fasterxml.jackson.module</groupId>
  <artifactId>jackson-module-scala_${scala.binary.version}</artifactId>
  <version>2.11.0</version>
</dependency>
Gradle
versions += [
  ScalaBinary: "2.13"
]
dependencies {
  compile group: 'com.fasterxml.jackson.module', name: "jackson-module-scala_${versions.ScalaBinary}", version: '2.11.0'
}

It is recommended (but not required) to use Terse Logback on the backend. Please see the documentation for what modules are appropriate for your use case.

The source code for this page can be found here.