A simple, contextual logging framework for Scala.
The maven repo is part of the git repo so, thanks to github's raw URL support, you can point SBT at...
resolvers ++= Seq("Conlog Repository" at "https://raw.github.com/btab/ConLog/master/repo")
It's then a simple matter of adding the dependency (note the %% as this project follows the artifact naming convention of including the scala version against which it was compiled)...
libraryDependencies ++= Seq("com.bluetheta" %% "conlog" % "1.2")
Create a global logging object (probably in some root package of your project that's imported a lot to save on extra import statements)...
object Log extends com.bluetheta.conlog.Logger
Wire up one or more subscribers (otherwise logging will be a no-op)...
object Application extends App {
Log.subscribe(SimpleLogReporter(System.out))
}
Log something...
Log.debug("memory usage at 20%")
Log.error("bad request")
Log.fatal("CPU overheat")
Log.info("processed 20/200 files")
Log.warn("option 3 is deprecated")
Provide a locator object. This concept emerged from the idea of parsing files and wanting to log a problem together with the location in the parsed file it occurred in. So for example...
case class SourceFileLine(line: String, lineNum: Int, file: File) extends com.bluetheta.conlog.LogLocator {
def location = file.getPath + ":" + lineNum
}
val line = SourceFileLine(rawLine, 22, file)
Log.error("unable to parse declaration", line)
Log within a context. If a fullblown workflow engine is overkill for your project, this feature provides a non-threadsafe mechanism to place the global logger in a nestable context. It allows for logging as though the workflow of your application were divided up into tasks and sub-tasks without the rigour of actually doing so...
// we start in the RootContext
Log.pushContext("Scanning images") // ctx 1
// all logging here will have ctx 1
Log.pushContext("Scanning JPEGs") // ctx2
// all logging here will have ctx 2 (inside ctx 1)
Log.popContext("59 JPEGs") // exiting ctx2 with a summary
Log.popContext // exiting ctx1 with no summary
Log.popContext // will throw an error