Created
December 25, 2011 04:23
-
-
Save j5ik2o/1518723 to your computer and use it in GitHub Desktop.
こんな構文で階層型のログ出力をしたい
This file contains 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
def connect = { | |
log("connect") { // connect start | |
// ... 何かの処理 ... | |
log("login") { // connect : login start | |
// ... 何かの処理 ... | |
} // connect : login end | |
// ... 何かの処理 ... | |
} // connect end | |
} | |
// implicit parameterで実現しればいいのかな... でも、名前が2種類になるのはダサいなー、、、logという名前で統一的に実現できればいいけど無理かなー | |
import LogOps._ | |
def connect = { | |
logHasChild("connect") { implicit ctx => // connect start | |
// ... 何かの処理 ... | |
logChild("login")/* (ctx) */ { // connect : login start | |
// ... 何かの処理 ... | |
} // connect : login end | |
// ... 何かの処理 ... | |
} // connect end | |
} | |
import grizzled.slf4j.Logging | |
object LogOps extends Logging { | |
def logHasChild[T](msg: String)(f: String => T): T = { | |
debug("%s : start".format(msg)) | |
val r = f(msg) | |
debug("%s : finish".format(msg)) | |
r | |
} | |
def logChild[T](msg: String)(f: => T)(implicit ctx: String): T = { | |
debug("%s : %s : start".format(ctx, msg)) | |
val r = f | |
debug("%s : %s : finish".format(ctx, msg)) | |
r | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment