Skip to content

Commit

Permalink
annotations for logger
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon committed Oct 31, 2024
1 parent 869db6f commit f2b8633
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ final class ZioLoggerRuntime(runtime: Runtime[Any], filter: LogFilter[Any]) exte
runtime.fiberRefs.joinAs(fiberId)(currentFiber.unsafe.getFiberRefs())
}

val logSpan = zio.LogSpan(logger.name, java.lang.System.currentTimeMillis())
val loggerName = (zio.logging.loggerNameAnnotationKey -> logger.name)
val logSpan = zio.LogSpan(logger.name, java.lang.System.currentTimeMillis())

val fiberRefs = currentFiberRefs
.updatedAs(fiberId)(FiberRef.currentLogSpan, logSpan :: currentFiberRefs.getOrDefault(FiberRef.currentLogSpan))
.updatedAs(fiberId)(
FiberRef.currentLogAnnotations,
currentFiberRefs.getOrDefault(FiberRef.currentLogAnnotations) + loggerName
currentFiberRefs.getOrDefault(FiberRef.currentLogAnnotations) ++ logger.annotations
)

val fiberRuntime = zio.internal.FiberRuntime(fiberId, fiberRefs, runtime.runtimeFlags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ final class ZioLoggerRuntime(runtime: Runtime[Any], filter: LogFilter[Any]) exte
runtime.fiberRefs.joinAs(fiberId)(currentFiber.unsafe.getFiberRefs())
}

val logSpan = zio.LogSpan(logger.name, java.lang.System.currentTimeMillis())
val loggerName = (zio.logging.loggerNameAnnotationKey -> logger.name)
val logAnnotations = if (keyValues != null) {
keyValues.asScala.map(kv => (kv.key, kv.value.toString)).toMap
val logSpan = zio.LogSpan(logger.name, java.lang.System.currentTimeMillis())

val logAnnotations = if (keyValues != null && !keyValues.isEmpty) {
keyValues.asScala.map(kv => (kv.key, kv.value.toString)).toMap ++ logger.annotations
} else {
Map.empty
logger.annotations
}

val fiberRefs = currentFiberRefs
.updatedAs(fiberId)(FiberRef.currentLogSpan, logSpan :: currentFiberRefs.getOrDefault(FiberRef.currentLogSpan))
.updatedAs(fiberId)(
FiberRef.currentLogAnnotations,
currentFiberRefs.getOrDefault(FiberRef.currentLogAnnotations) ++ logAnnotations + loggerName
currentFiberRefs.getOrDefault(FiberRef.currentLogAnnotations) ++ logAnnotations
)

val fiberRuntime = zio.internal.FiberRuntime(fiberId, fiberRefs, runtime.runtimeFlags)
Expand Down

0 comments on commit f2b8633

Please sign in to comment.