Skip to content

Instantly share code, notes, and snippets.

@x7c1
Created January 24, 2017 23:13
Show Gist options
  • Select an option

  • Save x7c1/9ba172a8822c52813ac031febf8a7b9b to your computer and use it in GitHub Desktop.

Select an option

Save x7c1/9ba172a8822c52813ac031febf8a7b9b to your computer and use it in GitHub Desktop.
Ruby's Object#tap by Scala
package x7c1.wheat.splicer.core.logger
object Tap {
object implicits {
implicit class Provider[A](val target: A) extends AnyVal {
def tap(f: (A => Unit)*): A = {
f foreach (_ (target))
target
}
}
}
}
import x7c1.wheat.splicer.core.logger.Tap.implicits.Provider
val policy = new TimeBasedRollingPolicy[ILoggingEvent]().tap(
_ setFileNamePattern """logs/app.%d{yyyy-MM-dd}.log""",
_ setMaxHistory 7,
_ setContext context,
_ setParent new FileAppender[ILoggingEvent]().tap(
_ setFile "logs/app.log"
),
_ start()
)
new RollingFileAppender[ILoggingEvent]().tap(
_ setEncoder encoder,
_ setContext context,
_ setRollingPolicy policy,
_ start()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment