Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:24
Show Gist options
  • Select an option

  • Save dacr/cbe9c2b235c93623013eae94b4ebba01 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/cbe9c2b235c93623013eae94b4ebba01 to your computer and use it in GitHub Desktop.
ZIO learning - using zio logging great features / published by https://github.com/dacr/code-examples-manager #5dd422d4-9a90-4450-bd24-23a46ee351b9/3b7960f79c619e09c6a63d9cbebaa2826d5fe4a3
// summary : ZIO learning - using zio logging great features
// keywords : scala, zio, learning, logging, pure-functional, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : 5dd422d4-9a90-4450-bd24-23a46ee351b9
// created-on : 2022-06-30T22:08:34+02:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.4.2"
//> using dep "dev.zio::zio:2.0.13"
//> using dep "dev.zio::zio-logging:2.1.13"
// ---------------------
import zio.*
import zio.logging.*
import ZIOAspect.*
object Encapsulated extends ZIOAppDefault {
val doThat =
ZIO.logSpan("doThat") {
ZIO.succeed(true) @@ logged("result")
}
val getIt =
ZIO.logSpan("processThat") {
for {
x <- ZIO.succeed(42)
_ <- doThat
_ <- ZIO.logInfo(s"$x has been received")
} yield x
}
val myapp =
ZIO.logSpan("myapp") {
for {
_ <- ZIO.logInfo("Application has started")
_ <- ZIO.logWarning("Configuration is wrong")
userId <- Random.nextUUID
result <- getIt @@ annotated("userId" -> userId.toString) @@ logged("getIt result") // The result is appended :) Great !!!
_ <- ZIO.logInfo("Application has finished")
} yield ()
}
def run = myapp
}
Encapsulated.main(Array.empty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment