Git Product home page Git Product logo

scalalogging's Introduction

ScalaLogging

Scala logging library wrapping SLF4J and Log4j 2 in a convenient and performant fashion.

In principle the call of log messages should be avoided if the given log level is not enabled. Hence we should write the following code to log at the debug level:

if (logger.isDebugEnabled) logger.debug(s"Some ${expensiveExpression} message!")

This is even true in the presence of parameterized log methods like available for Logback, at least if readability matters:

if (logger.isDebugEnabled) logger.debug("Some {} message!", expensiveExpression)

Yet this idiom is too heavyweight, so that many of us just omit the isEnabled-check. Fortunately Scala macros can be used to make our lives easier: ScalaLogging offers the class Logger with lightweight logging methods that will be expanded to the above idiom. So all we have to write is:

logger.debug(s"Some ${expensiveExpression} message!")

After the macro has been applied, the code will have been transformed into the above described idiom.

In addition ScalaLogging offers the trait Logging which conveniently provides a Logger instance initialized with the name of the class mixed into:

class MyClass extends Logging {
  logger.debug("This is very convenient ;-)")
}

Prerequisites

  • Scala 2.10.0
  • SLF4J 1.7.2 or Log4j 2.0-beta3

Using ScalaLogging

ScalaLogging is published to the Sonatype OSS snapshot and release repositories. As the Sonatype OSS release repository is mirrored to Maven Central (with a certain delay), you can use releases without adding custom resolvers to your sbt build definition or custom repositories to your Maven POM. The group id (organization) is com.typesafe and the artifact ids (names) are scalalogging-slf4j and scalalogging-log4j.

The following example shows how to add a dependency to the latest release version of ScalaLogging to your sbt (0.12.x) build definition:

libraryDependencies += "com.typesafe" %% "scalalogging-slf4j" % "1.0.1"

The following example shows how to add a dependency to the latest snapshot version of ScalaLogging to your sbt (0.12.x) build definition:

resolvers += Opts.resolver.sonatypeSnapshots

libraryDependencies += "com.typesafe" %% "scalalogging-log4j" % "1.1.0-SNAPSHOT"

Contribution policy

Contributions via GitHub pull requests are gladly accepted from their original author. Before we can accept pull requests, you will need to agree to the Typesafe Contributor License Agreement online, using your GitHub account.

License

This code is open source software licensed under the Apache 2.0 License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.