{"id":15159374,"url":"https://github.com/mattroberts297/slf4s","last_synced_at":"2025-08-19T23:06:23.391Z","repository":{"id":13860974,"uuid":"16558746","full_name":"mattroberts297/slf4s","owner":"mattroberts297","description":"A Simple Logging Facade for Scala","archived":false,"fork":false,"pushed_at":"2019-06-17T17:35:21.000Z","size":466,"stargazers_count":15,"open_issues_count":4,"forks_count":6,"subscribers_count":3,"default_branch":"2.12","last_synced_at":"2025-01-16T04:21:30.533Z","etag":null,"topics":["logging","macros","scala"],"latest_commit_sha":null,"homepage":"http://slf4s.org/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattroberts297.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-05T21:19:46.000Z","updated_at":"2019-11-26T21:50:46.000Z","dependencies_parsed_at":"2022-08-25T19:21:01.941Z","dependency_job_id":null,"html_url":"https://github.com/mattroberts297/slf4s","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattroberts297%2Fslf4s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattroberts297%2Fslf4s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattroberts297%2Fslf4s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattroberts297%2Fslf4s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattroberts297","download_url":"https://codeload.github.com/mattroberts297/slf4s/tar.gz/refs/heads/2.12","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236455678,"owners_count":19151519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logging","macros","scala"],"created_at":"2024-09-26T21:05:19.274Z","updated_at":"2025-02-09T18:31:03.970Z","avatar_url":"https://github.com/mattroberts297.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/mattroberts297/slf4s.svg?branch=2.12)](https://travis-ci.org/mattroberts297/slf4s) [![Coverage Status](https://coveralls.io/repos/mattroberts297/slf4s/badge.svg?branch=2.12)](https://coveralls.io/r/mattroberts297/slf4s?branch=2.12)\n\n# About\nA Simple Logging Facade for Scala (SLF4S) built on top of SLF4J.\n\n# Features\n* Call by macro expansion (call by name in Scala 2.9);\n* A Logging mixin for conveniently obtaining a Logger;\n* A LoggerFactory that is `ClassTag` aware;\n* Built for Scala 2.9, 2.10 and 2.11;\n* Tested on Java 6, 7 and 8; and\n* Tracks [slf4j](http://www.slf4j.org/) releases.\n\nThe use of macros means that calls to `log.debug` are expanded into `if (log.isDebugEnabled) log.debug` at compile time.\n\n# Installation\n### Build.scala\n```scala\nlibraryDependencies ++= Seq(\n  \"org.slf4s\" %% \"slf4s-api\" % \"1.7.12\",\n  \"ch.qos.logback\" % \"logback-classic\" % \"1.1.2\"\n)\n```\n\nYou don't have to use [logback](http://logback.qos.ch/), any [slf4j](http://www.slf4j.org/) compatible framework will do.\n\n# Usage\n### The Logging Trait\nThe `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.\n```scala\npackage org.slf4s\n\nimport org.scalatest.WordSpec\n\nclass LoggingExampleSpec extends WordSpec with Logging {\n  \"The Logging trait should be easy to use\" in {\n    val importantValue = 10\n    log.debug(s\"importantValue: $importantValue\")\n    val importantThrowable = new Throwable\n    log.debug(s\"importantValue: $importantValue\", importantThrowable)\n  }\n}\n```\n\n### The LoggerFactory Object\nThe `LoggerFactory` gives you great flexibility and behaves much like the [slf4j](http://www.slf4j.org/) LoggerFactory. You probably only need to use this if you wish to log as a class other than the one in scope.\n``` scala\npackage org.slf4s\n\nimport org.scalatest.WordSpec\n\nclass LoggerFactoryExampleSpec extends WordSpec {\n  \"The LoggerFactory should be familiar\" in {\n    val log = LoggerFactory.getLogger[LoggerFactoryExampleSpec]\n    val importantValue = 10\n    log.debug(s\"importantValue: $importantValue\")\n    val importantThrowable = new Throwable\n    log.debug(s\"importantValue: $importantValue\", importantThrowable)\n  }\n}\n```\n\n### String Interpolation\nScala 2.10.0 offers a new mechanism to create strings from your data: [String Interpolation](http://docs.scala-lang.org/overviews/core/string-interpolation.html). This allows you to to embed variable references and expressions directly in processed string literals.\n\n``` scala\npackage org.slf4s\n\nimport org.scalatest.WordSpec\n\nclass StringInterpolatorExampleSpec extends WordSpec with Logging {\n\n  \"String interpolation should work\" in {\n    val name = \"James\"\n    val height = 1.9d\n    log.debug(s\"Hello, $name\")  // Hello, James\n    log.debug(s\"1 + 1 = ${1 + 1}\") // 1 + 1 = 2\n    log.debug(f\"$name%s is $height%2.2f meters tall\")  // James is 1.90 meters tall\n    log.debug(raw\"a\\nb\") // New line is preserved\n  }\n}\n```\n\n### The Underlying Field\nThe [`Logger`](http://slf4s.org/api/1.7.12/#org.slf4s.Logger) instance exposes an [`underlying`](http://slf4s.org/api/1.7.12/index.html#org.slf4s.Logger@underlying:org.slf4j.Logger) field that enables you to call slf4j methods directly. This is useful if you wish to avoid a macro expansion for some reason.\n\n# Documentation\nFor those who prefer not to use an IDE, I've made the [ScalaDoc](http://slf4s.org/api/1.7.12/) available online.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattroberts297%2Fslf4s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattroberts297%2Fslf4s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattroberts297%2Fslf4s/lists"}