Created
February 11, 2020 20:53
-
-
Save vhutov/94b2665fbd81914bd579b0ea80395a92 to your computer and use it in GitHub Desktop.
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
object Sequential extends IOApp { | |
private val log: Logger[IO] = Slf4jLogger.getLogger[IO].mdc | |
override def run(args: List[String]): IO[ExitCode] = { | |
for { | |
_ <- log.info("Start") | |
user <- op.withLogContext(_.id("1")) | |
_ <- log.info(s"result: $user") | |
_ <- log.info("End") | |
} yield ExitCode.Success | |
} | |
private def op: IO[String] = { | |
for { | |
_ <- log.info("op start") | |
result <- opInner.withLogContext(_.tpe("inner")) | |
_ <- log.info("op end") | |
} yield result | |
} | |
private def opInner: IO[String] = | |
for { | |
_ <- log.info("op_inner start") | |
result <- IO("user") | |
_ <- log.info("op_inner end") | |
} yield result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment