slf4s-api


License

License

MIT
GroupId

GroupId

org.slf4s
ArtifactId

ArtifactId

slf4s-api_2.9.1-1
Last Version

Last Version

1.7.13
Release Date

Release Date

Type

Type

jar
Description

Description

slf4s-api
slf4s-api
Project URL

Project URL

http://slf4s.org/
Project Organization

Project Organization

org.slf4s
Source Code Management

Source Code Management

https://github.com/mattroberts297/slf4s

Download slf4s-api_2.9.1-1

How to add to project

<!-- https://jarcasting.com/artifacts/org.slf4s/slf4s-api_2.9.1-1/ -->
<dependency>
    <groupId>org.slf4s</groupId>
    <artifactId>slf4s-api_2.9.1-1</artifactId>
    <version>1.7.13</version>
</dependency>
// https://jarcasting.com/artifacts/org.slf4s/slf4s-api_2.9.1-1/
implementation 'org.slf4s:slf4s-api_2.9.1-1:1.7.13'
// https://jarcasting.com/artifacts/org.slf4s/slf4s-api_2.9.1-1/
implementation ("org.slf4s:slf4s-api_2.9.1-1:1.7.13")
'org.slf4s:slf4s-api_2.9.1-1:jar:1.7.13'
<dependency org="org.slf4s" name="slf4s-api_2.9.1-1" rev="1.7.13">
  <artifact name="slf4s-api_2.9.1-1" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.slf4s', module='slf4s-api_2.9.1-1', version='1.7.13')
)
libraryDependencies += "org.slf4s" % "slf4s-api_2.9.1-1" % "1.7.13"
[org.slf4s/slf4s-api_2.9.1-1 "1.7.13"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.9.1-1
org.slf4j : slf4j-api jar 1.7.13

Project Modules

There are no modules declared in this project.

Build Status Coverage Status

About

A Simple Logging Facade for Scala (SLF4S) built on top of SLF4J.

Features

  • Call by macro expansion (call by name in Scala 2.9);
  • A Logging mixin for conveniently obtaining a Logger;
  • A LoggerFactory that is ClassTag aware;
  • Built for Scala 2.9, 2.10 and 2.11;
  • Tested on Java 6, 7 and 8; and
  • Tracks slf4j releases.

The use of macros means that calls to log.debug are expanded into if (log.isDebugEnabled) log.debug at compile time.

Installation

Build.scala

libraryDependencies ++= Seq(
  "org.slf4s" %% "slf4s-api" % "1.7.12",
  "ch.qos.logback" % "logback-classic" % "1.1.2"
)

You don't have to use logback, any slf4j compatible framework will do.

Usage

The Logging Trait

The Logging trait provides a protected val log to your class, so it'll be available in the local scope, but won't pollute your interface. You can also reference it via a self type if you're using the cake pattern.

package org.slf4s

import org.scalatest.WordSpec

class LoggingExampleSpec extends WordSpec with Logging {
  "The Logging trait should be easy to use" in {
    val importantValue = 10
    log.debug(s"importantValue: $importantValue")
    val importantThrowable = new Throwable
    log.debug(s"importantValue: $importantValue", importantThrowable)
  }
}

The LoggerFactory Object

The LoggerFactory gives you great flexibility and behaves much like the slf4j LoggerFactory. You probably only need to use this if you wish to log as a class other than the one in scope.

package org.slf4s

import org.scalatest.WordSpec

class LoggerFactoryExampleSpec extends WordSpec {
  "The LoggerFactory should be familiar" in {
    val log = LoggerFactory.getLogger[LoggerFactoryExampleSpec]
    val importantValue = 10
    log.debug(s"importantValue: $importantValue")
    val importantThrowable = new Throwable
    log.debug(s"importantValue: $importantValue", importantThrowable)
  }
}

String Interpolation

Scala 2.10.0 offers a new mechanism to create strings from your data: String Interpolation. This allows you to to embed variable references and expressions directly in processed string literals.

package org.slf4s

import org.scalatest.WordSpec

class StringInterpolatorExampleSpec extends WordSpec with Logging {

  "String interpolation should work" in {
    val name = "James"
    val height = 1.9d
    log.debug(s"Hello, $name")  // Hello, James
    log.debug(s"1 + 1 = ${1 + 1}") // 1 + 1 = 2
    log.debug(f"$name%s is $height%2.2f meters tall")  // James is 1.90 meters tall
    log.debug(raw"a\nb") // New line is preserved
  }
}

The Underlying Field

The Logger instance exposes an underlying field that enables you to call slf4j methods directly. This is useful if you wish to avoid a macro expansion for some reason.

Documentation

For those who prefer not to use an IDE, I've made the ScalaDoc available online.

Versions

Version
1.7.13
1.7.12
1.7.10