diff --git a/integration/src/test/scala/org/knora/webapi/testcontainers/DspIngestTestContainer.scala b/integration/src/test/scala/org/knora/webapi/testcontainers/DspIngestTestContainer.scala index 8889240af7..436fdb5f9a 100644 --- a/integration/src/test/scala/org/knora/webapi/testcontainers/DspIngestTestContainer.scala +++ b/integration/src/test/scala/org/knora/webapi/testcontainers/DspIngestTestContainer.scala @@ -11,7 +11,7 @@ import zio.URLayer import zio.ZIO import zio.ZLayer -import org.knora.webapi.testcontainers.TestContainerOps.StartableOps +import org.knora.webapi.testcontainers.TestContainerOps.toZio final class DspIngestTestContainer extends GenericContainer[DspIngestTestContainer](s"daschswiss/dsp-ingest:latest") @@ -43,5 +43,5 @@ object DspIngestTestContainer { ) val layer: URLayer[SharedVolumes.Images, DspIngestTestContainer] = - ZLayer.scoped(ZIO.service[SharedVolumes.Images].flatMap(make(_).toZio)) >+> initDspIngest + ZLayer.scoped(ZIO.serviceWithZIO[SharedVolumes.Images](make(_).toZio)) >+> initDspIngest } diff --git a/integration/src/test/scala/org/knora/webapi/testcontainers/FusekiTestContainer.scala b/integration/src/test/scala/org/knora/webapi/testcontainers/FusekiTestContainer.scala index 32141462f2..6228b51698 100644 --- a/integration/src/test/scala/org/knora/webapi/testcontainers/FusekiTestContainer.scala +++ b/integration/src/test/scala/org/knora/webapi/testcontainers/FusekiTestContainer.scala @@ -21,7 +21,7 @@ import java.net.http.HttpRequest.BodyPublishers import java.net.http.HttpResponse.BodyHandlers import org.knora.webapi.http.version.BuildInfo -import org.knora.webapi.testcontainers.TestContainerOps.StartableOps +import org.knora.webapi.testcontainers.TestContainerOps.toLayer final class FusekiTestContainer extends GenericContainer[FusekiTestContainer](BuildInfo.fuseki) { diff --git a/integration/src/test/scala/org/knora/webapi/testcontainers/SipiTestContainer.scala b/integration/src/test/scala/org/knora/webapi/testcontainers/SipiTestContainer.scala index 6899894396..9fbf873440 100644 --- a/integration/src/test/scala/org/knora/webapi/testcontainers/SipiTestContainer.scala +++ b/integration/src/test/scala/org/knora/webapi/testcontainers/SipiTestContainer.scala @@ -18,7 +18,7 @@ import java.net.Inet6Address import java.net.InetAddress import org.knora.webapi.http.version.BuildInfo -import org.knora.webapi.testcontainers.TestContainerOps.StartableOps +import org.knora.webapi.testcontainers.TestContainerOps.toZio final class SipiTestContainer extends GenericContainer[SipiTestContainer](s"daschswiss/knora-sipi:${BuildInfo.version}") { @@ -83,7 +83,7 @@ object SipiTestContainer { ) val layer: URLayer[SharedVolumes.Images, SipiTestContainer] = { - val container = ZLayer.scoped(ZIO.service[SharedVolumes.Images].flatMap(make(_).toZio)) + val container = ZLayer.scoped(ZIO.serviceWithZIO[SharedVolumes.Images](make(_).toZio)) (container >>> initSipi).orDie } } diff --git a/integration/src/test/scala/org/knora/webapi/testcontainers/TestContainerOps.scala b/integration/src/test/scala/org/knora/webapi/testcontainers/TestContainerOps.scala index fc0da54f2a..f6137dc2aa 100644 --- a/integration/src/test/scala/org/knora/webapi/testcontainers/TestContainerOps.scala +++ b/integration/src/test/scala/org/knora/webapi/testcontainers/TestContainerOps.scala @@ -10,18 +10,17 @@ import zio.* object ZioTestContainers { - def toZio[T <: Startable](self: T): URIO[Scope, T] = { // using `logError.ignore` because there's no point to try to recover if starting/stopping the container fails - val acquire = ZIO.attemptBlocking(self.start()).logError.ignore.as(self) - val release = (container: T) => ZIO.attemptBlocking(container.stop()).logError.ignore + def toZio[T <: Startable](self: T): URIO[Scope, T] = { + val acquire = ZIO.attemptBlocking(self.start()).orDie.as(self) + val release = (container: T) => ZIO.succeed(container.stop()) ZIO.acquireRelease(acquire)(release) } - def toLayer[T <: Startable: Tag](container: T): ULayer[T] = - ZLayer.scoped(toZio(container)) + def toLayer[T <: Startable: Tag](self: T): ULayer[T] = ZLayer.scoped(toZio(self)) } object TestContainerOps { - implicit final class StartableOps[T <: Startable](private val self: T) extends AnyVal { + extension [T <: Startable](self: T) { def toZio: URIO[Scope, T] = ZioTestContainers.toZio(self) def toLayer(implicit ev: Tag[T]): ULayer[T] = ZioTestContainers.toLayer(self) } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index a79a05ac04..c942166335 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -29,7 +29,7 @@ object Dependencies { val ZioMetricsConnectorsVersion = "2.3.1" val ZioPreludeVersion = "1.0.0-RC24" val ZioSchemaVersion = "0.2.0" - val ZioVersion = "2.0.22" + val ZioVersion = "2.1.1" // ZIO val zio = "dev.zio" %% "zio" % ZioVersion diff --git a/project/build.properties b/project/build.properties index 04267b14af..081fdbbc76 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.9 +sbt.version=1.10.0 diff --git a/project/plugins.sbt b/project/plugins.sbt index ee74ec56d1..23edfd3f1d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -10,5 +10,5 @@ addSbtPlugin("com.github.sbt" % "sbt-javaagent" % "0.1.8") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0") diff --git a/webapi/src/main/scala/org/knora/webapi/util/Logger.scala b/webapi/src/main/scala/org/knora/webapi/util/Logger.scala index 4b57be7a52..ec5263dd0c 100644 --- a/webapi/src/main/scala/org/knora/webapi/util/Logger.scala +++ b/webapi/src/main/scala/org/knora/webapi/util/Logger.scala @@ -35,32 +35,22 @@ object Logger { label("spans", bracketed(spans)) + (space + label("cause", cause).highlight).filter(LogFilter.causeNonEmpty) - private val textLogger: ZLayer[Any, Nothing, Unit] = consoleLogger( - ConsoleLoggerConfig(logFormatText, logFilter), - ) - private val logFormatJson: LogFormat = LogFormat.label("name", LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat()) + LogFormat.default + LogFormat.annotations + LogFormat.spans - private val jsonLogger: ZLayer[Any, Nothing, Unit] = consoleJsonLogger( - ConsoleLoggerConfig(logFormatJson, logFilter), - ) + private val textLogger: ULayer[Unit] = consoleLogger(ConsoleLoggerConfig(logFormatText, logFilter)) + private val jsonLogger: ULayer[Unit] = consoleJsonLogger(ConsoleLoggerConfig(logFormatJson, logFilter)) private val useJsonLogger = sys.env.getOrElse("DSP_API_LOG_APPENDER", "TEXT") == "JSON" - private val logger: ZLayer[Any, Nothing, Unit] = - if (useJsonLogger) jsonLogger - else textLogger + private val logger: ULayer[Unit] = if (useJsonLogger) jsonLogger else textLogger - def fromEnv(): ZLayer[Any, Nothing, Unit & Unit] = - Runtime.removeDefaultLoggers >>> logger >+> Slf4jBridge.initialize + def fromEnv(): ULayer[Unit] = Runtime.removeDefaultLoggers >>> logger >+> Slf4jBridge.initialize - def json(): ZLayer[Any, Nothing, Unit & Unit] = - Runtime.removeDefaultLoggers >>> jsonLogger >+> Slf4jBridge.initialize + def json(): ULayer[Unit] = Runtime.removeDefaultLoggers >>> jsonLogger >+> Slf4jBridge.initialize - def text(): ZLayer[Any, Nothing, Unit & Unit] = - Runtime.removeDefaultLoggers >>> textLogger >+> Slf4jBridge.initialize + def text(): ULayer[Unit] = Runtime.removeDefaultLoggers >>> textLogger >+> Slf4jBridge.initialize }