Skip to content

Instantly share code, notes, and snippets.

@ymasory
Forked from gseitz/RetroLogger.scala
Created September 16, 2011 05:14
Show Gist options
  • Save ymasory/1221251 to your computer and use it in GitHub Desktop.
Save ymasory/1221251 to your computer and use it in GitHub Desktop.
RetroLogger - Bringing old school log level commands to sbt-0.10.x
/* RetroLogger.scala
*
* A handy sbt-0.10.x plugin that allows you to set the log level like in the
* old days (AKA sbt-0.7.x).
*
* It works by creating aliases of this form:
* "set logLevel := Level.Debug" ====> "debug"
*
* Installation:
* - mkdir -p ~/.sbt/plugins/
* - cp path/to/RetroLogger.scala ~/.sbt/plugins/
* - touch ~/.sbt/plugins/build.sbt
* - add "sbtPlugin := true" to ~/.sbt/plugins/build.sbt
*
* Author: Gerolf Seitz
* Original: https://gist.github.com/1100428
*/
import sbt._
import Keys._
object RetroLogger extends Plugin {
private def log(level: String) = (state: State) =>
BuiltinCommands.addAlias (
state, level,
"set logLevel := Level.%s%s" format (level.head.toUpper, level.tail)
)
// The workaround from above.
override lazy val settings: Seq[Setting[_]] = Seq[Setting[_]] (
onLoad in Global <<= (onLoad in Global) ?? identity[State],
onLoad in Global ~= { oldState =>
log("error") compose
log("warn") compose
log("info") compose
log("debug") compose
oldState
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment