Skip to content
This repository was archived by the owner on May 21, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ crossScalaVersions := Seq(
"2.9.0-1",
"2.9.1")


libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "1.6.1")

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Logging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ trait Logging {
/**
* Logger for the type mixed into.
*/
protected[slf4s] lazy val logger = Logger(this.getClass)
protected[slf4s] implicit lazy val logger = Logger(this.getClass)
}
45 changes: 45 additions & 0 deletions src/main/scala/LoggingUtilities.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.weiglewilczek.slf4s

/*
* A mixin with logging utilities.
*/
trait LoggingUtilities {
implicit def wrapAny[A](value: A) = new AnyWrapper(value)

class AnyWrapper[A](value: A) {

/**
* This is a logging version of Kestrel combinator.
*
* This method is very similar to Object#tap method in Ruby. It prints the given message along with the object
* on which the method was invoked, and evaluates to the same object. It is used to tap into method chains, in
* in order to inspect the values of object at various stages in processing.
*
* Example:
* List.range(1, 10).trace("Original")
* .map(2 *).trace("After mapping")
* .filter(4 <).trace("After filtering")
* .size.trace("Size")
*
* The default logging method invoked is Logger#debug. It is easy to invoke other logging methods instead, if
* so required.
*
* Example:
* List.range(1, 10).trace("Original", _.info)
*
* @param message The message to be logged along with the object value.
* @param logFn The logging method to use. By default, set to Logger#debug.
* @param logger The logger to use for logging.
* @return The object on which the method was invoked.
*/
def trace(message: => String, logFn: Logger => (=> String) => Unit = _.debug)(implicit logger: Logger): A = {
logFn(logger)(message + ": " + value)
value
}
}
}

/*
* A first class module that provides logging utilities.
*/
object LoggingUtilities extends LoggingUtilities