Created
January 24, 2017 23:13
-
-
Save x7c1/9ba172a8822c52813ac031febf8a7b9b to your computer and use it in GitHub Desktop.
Ruby's Object#tap by Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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