Skip to content

Commit

Permalink
Feat: Move logging to ZIO's official logging library
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Hall <[email protected]>
  • Loading branch information
j-hall-mwam committed Dec 4, 2023
1 parent a2b969c commit 67cc3f8
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 606 deletions.
47 changes: 22 additions & 25 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
val orgName = "Marshall Wace"
val year = 2023

ThisBuild / scalaVersion := "3.3.1"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "com.mwam.kafkakewl"
ThisBuild / organizationName := orgName
ThisBuild / startYear := Some(year)

ThisBuild / scalacOptions ++= Seq(
"-Xmax-inlines", "64",
ThisBuild / scalaVersion := "3.3.1"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "com.mwam.kafkakewl"
ThisBuild / organizationName := orgName
ThisBuild / startYear := Some(year)

ThisBuild / scalacOptions ++= Seq(
"-Xmax-inlines",
"64",
"-Yretain-trees", // so that zio-json supports default values
"-Wunused:imports", "-Wunused:params", "-deprecation", "-feature"
"-Wunused:imports",
"-Wunused:params",
"-deprecation",
"-feature"
)

// Have to do this for the root project and enable it for the sub-projects as well as setting the headerLicense for them.
disablePlugins(HeaderPlugin)

val license = Some(HeaderLicense.Custom(
s"""SPDX-FileCopyrightText: $year $orgName <[email protected]>
val license = Some(HeaderLicense.Custom(s"""SPDX-FileCopyrightText: $year $orgName <[email protected]>
|
|SPDX-License-Identifier: Apache-2.0
|""".stripMargin
))
|""".stripMargin))

val logbackVersion = "1.4.11"
val logbackContribJsonVersion = "0.1.5"
Expand All @@ -44,7 +46,7 @@ val tapir = Seq(
"com.softwaremill.sttp.tapir" %% "tapir-zio-http-server" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-json-zio" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-zio-metrics" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-zio-metrics" % tapirVersion
)

val tapirCore = Seq(
Expand All @@ -63,7 +65,7 @@ val zio = Seq(
"dev.zio" %% "zio-test-junit" % zioVersion % Test,
"dev.zio" %% "zio-json" % zioJsonVersion,
"dev.zio" %% "zio-logging" % zioLoggingVersion,
"dev.zio" %% "zio-logging-slf4j" % zioLoggingVersion,
"dev.zio" %% "zio-logging-slf4j2-bridge" % zioLoggingVersion,
"dev.zio" %% "zio-kafka" % zioKafkaVersion,
"com.softwaremill.sttp.client3" %% "zio-json" % tapirZioJsonVersion % Test
)
Expand All @@ -75,18 +77,13 @@ val config = Seq(
)

val circeYaml = Seq(
"io.circe" %% "circe-yaml" % circeYamlVersion
"io.circe" %% "circe-yaml" % circeYamlVersion
)

val kafkaClient = Seq(
"org.apache.kafka" % "kafka-clients" % kafkaClientVersion
)

val logging = Seq(
"ch.qos.logback" % "logback-classic" % logbackVersion,
"ch.qos.logback.contrib" % "logback-jackson" % logbackContribJsonVersion
)

val telemetry = Seq(
"dev.zio" %% "zio-opentelemetry" % zioTelemetryVersion,
"io.opentelemetry" % "opentelemetry-api" % openTelemetryVersion,
Expand All @@ -95,7 +92,7 @@ val telemetry = Seq(
"io.opentelemetry" % "opentelemetry-extension-trace-propagators" % openTelemetryVersion,
"io.opentelemetry" % "opentelemetry-semconv" % s"$openTelemetryVersion-alpha",
"io.opentelemetry" % "opentelemetry-sdk-extension-autoconfigure" % openTelemetryVersion,
"io.grpc" % "grpc-netty-shaded" % openTelemetryGrpcVersion,
"io.grpc" % "grpc-netty-shaded" % openTelemetryGrpcVersion
)

val tests = Seq(
Expand All @@ -108,7 +105,7 @@ lazy val utils = project
.settings(
name := "kafkakewl-utils",
headerLicense := license,
libraryDependencies ++= logging ++ zio ++ config
libraryDependencies ++= zio ++ config
)

lazy val domain = project
Expand Down Expand Up @@ -145,7 +142,7 @@ lazy val deploy = project
// disabling scalaDoc fixes it (it's needed because stage wants to generate scalaDoc)
packageDoc / publishArtifact := false,
Compile / mainClass := Some("com.mwam.kafkakewl.deploy.Main"),
libraryDependencies ++= tapir ++ tapirCore ++ config ++ zio ++ tests ++ logging,
libraryDependencies ++= tapir ++ tapirCore ++ config ++ zio ++ tests,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)

Expand All @@ -162,6 +159,6 @@ lazy val metrics = project
// disabling scalaDoc fixes it (it's needed because stage wants to generate scalaDoc)
packageDoc / publishArtifact := false,
Compile / mainClass := Some("com.mwam.kafkakewl.metrics.Main"),
libraryDependencies ++= tapir ++ tapirCore ++ config ++ zio ++ tests ++ logging,
libraryDependencies ++= tapir ++ tapirCore ++ config ++ zio ++ tests,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
113 changes: 0 additions & 113 deletions kafkakewl-deploy/src/main/resources/logback.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,27 @@ import com.mwam.kafkakewl.deploy.services.{TopologyDeploymentsService, TopologyD
import com.mwam.kafkakewl.domain.config.KafkaClientConfig
import sttp.tapir.server.metrics.zio.ZioMetrics
import sttp.tapir.server.ziohttp.{ZioHttpInterpreter, ZioHttpServerOptions}
import zio.*
import zio.http.Server
import zio.logging.LogFormat
import zio.logging.backend.SLF4J
import zio.metrics.connectors.prometheus
import zio.metrics.jvm.DefaultJvmMetrics
import zio.telemetry.opentelemetry.context.ContextStorage
import zio.telemetry.opentelemetry.tracing.Tracing
import com.mwam.kafkakewl.utils.logging.Logging.{deployLogger, localLogger}
import zio._

object Main extends ZIOAppDefault {

override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] =
Runtime.removeDefaultLoggers >>>
// TODO play with this more so that we support structured logging properly
SLF4J.slf4j(
LogFormat.make {
// For now we just append the message and the cause to the output (which will be the sl4fj message)
(builder, _, _, _, message, cause, _, _, _) =>
{
builder.appendText(message())
builder.appendCause(cause)
}
}
)
ZLayer.fromZIO {
ZIOAppArgs.getArgs
.map(args =>
if (args.mkString == "local") {
localLogger
} else {
deployLogger
}
)
}.flatten

override def run: ZIO[ZIOAppArgs with Scope, Any, Any] = {
val options: ZioHttpServerOptions[Any] = ZioHttpServerOptions.customiseInterceptors
Expand Down
113 changes: 0 additions & 113 deletions kafkakewl-metrics/src/main/resources/logback.xml

This file was deleted.

Loading

0 comments on commit 67cc3f8

Please sign in to comment.