Skip to content

Commit

Permalink
merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon committed Nov 23, 2023
1 parent 4add554 commit b3342f8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ object Slf4jBridge {
ZLayer {
for {
runtime <- ZIO.runtime[Any]
_ <- initLock.withPermit {
ZIO.succeed(ZioLoggerFactory.initialize(new ZioLoggerRuntime(runtime)))
}
_ <- initLock.withPermit {
ZIO.succeed(ZioLoggerFactory.initialize(new ZioLoggerRuntime(runtime)))
}
} yield ()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import zio.{ Cause, Chunk, LogLevel, ZIO, ZIOAspect }
object Slf4jBridgeSpec extends ZIOSpecDefault {

final case class LogEntry(
span: List[String],
level: LogLevel,
annotations: Map[String, String],
message: String,
cause: Cause[Any]
)
span: List[String],
level: LogLevel,
annotations: Map[String, String],
message: String,
cause: Cause[Any]
)

override def spec =
suite("Slf4jBridge")(
Expand Down Expand Up @@ -41,25 +41,25 @@ object Slf4jBridgeSpec extends ZIOSpecDefault {
val testFailure = new RuntimeException("test error")
for {
_ <- (for {
logger <- ZIO.attempt(org.slf4j.LoggerFactory.getLogger("test.logger"))
_ <- ZIO.logSpan("span")(ZIO.attempt(logger.debug("test debug message"))) @@ ZIOAspect
.annotated("trace_id", "tId")
_ <- ZIO.attempt(logger.warn("hello {}", "world")) @@ ZIOAspect.annotated("user_id", "uId")
_ <- ZIO.attempt(logger.warn("{}..{}..{} ... go!", "3", "2", "1"))
_ <- ZIO.attempt(logger.warn("warn cause", testFailure))
_ <- ZIO.attempt(logger.error("error", testFailure))
_ <- ZIO.attempt(logger.error("error", null))
} yield ()).exit
logger <- ZIO.attempt(org.slf4j.LoggerFactory.getLogger("test.logger"))
_ <- ZIO.logSpan("span")(ZIO.attempt(logger.debug("test debug message"))) @@ ZIOAspect
.annotated("trace_id", "tId")
_ <- ZIO.attempt(logger.warn("hello {}", "world")) @@ ZIOAspect.annotated("user_id", "uId")
_ <- ZIO.attempt(logger.warn("{}..{}..{} ... go!", "3", "2", "1"))
_ <- ZIO.attempt(logger.warn("warn cause", testFailure))
_ <- ZIO.attempt(logger.error("error", testFailure))
_ <- ZIO.attempt(logger.error("error", null))
} yield ()).exit
output <- ZTestLogger.logOutput
lines = output.map { logEntry =>
LogEntry(
logEntry.spans.map(_.label),
logEntry.logLevel,
logEntry.annotations,
logEntry.message(),
logEntry.cause
)
}
LogEntry(
logEntry.spans.map(_.label),
logEntry.logLevel,
logEntry.annotations,
logEntry.message(),
logEntry.cause
)
}
} yield assertTrue(
lines == Chunk(
LogEntry(
Expand Down Expand Up @@ -110,20 +110,20 @@ object Slf4jBridgeSpec extends ZIOSpecDefault {
test("logs through slf4j without fiber ref propagation") {
for {
_ <- (for {
logger <- ZIO.attempt(org.slf4j.LoggerFactory.getLogger("test.logger"))
_ <- ZIO.attempt(logger.debug("test debug message")) @@ ZIOAspect.annotated("trace_id", "tId")
_ <- ZIO.attempt(logger.warn("hello {}", "world")) @@ ZIOAspect.annotated("user_id", "uId")
} yield ()).exit
logger <- ZIO.attempt(org.slf4j.LoggerFactory.getLogger("test.logger"))
_ <- ZIO.attempt(logger.debug("test debug message")) @@ ZIOAspect.annotated("trace_id", "tId")
_ <- ZIO.attempt(logger.warn("hello {}", "world")) @@ ZIOAspect.annotated("user_id", "uId")
} yield ()).exit
output <- ZTestLogger.logOutput
lines = output.map { logEntry =>
LogEntry(
logEntry.spans.map(_.label),
logEntry.logLevel,
logEntry.annotations,
logEntry.message(),
logEntry.cause
)
}
LogEntry(
logEntry.spans.map(_.label),
logEntry.logLevel,
logEntry.annotations,
logEntry.message(),
logEntry.cause
)
}
} yield assertTrue(
lines == Chunk(
LogEntry(
Expand Down

0 comments on commit b3342f8

Please sign in to comment.