@@ -54,6 +54,31 @@ package object logging extends LoggerLayers {
5454 def loggerName (value : String ): ZIOAspect [Nothing , Any , Nothing , Any , Nothing , Any ] =
5555 ZIOAspect .annotated(loggerNameAnnotationKey, value)
5656
57+ /**
58+ * Logger name aspect, by this aspect is possible to set logger name (in general, logger name is extracted from [[Trace ]])
59+ *
60+ * annotation key: [[zio.logging.loggerNameAnnotationKey ]]
61+ */
62+ def loggerName (fn : Option [String ] => String ): ZIOAspect [Nothing , Any , Nothing , Any , Nothing , Any ] =
63+ new ZIOAspect [Nothing , Any , Nothing , Any , Nothing , Any ] {
64+ def apply [R , E , A ](zio : ZIO [R , E , A ])(implicit trace : Trace ): ZIO [R , E , A ] =
65+ for {
66+ annotations <- ZIO .logAnnotations
67+ currentLoggerName = annotations.get(loggerNameAnnotationKey)
68+ newLoggerName = fn(currentLoggerName)
69+ a <- ZIO .logAnnotate(loggerNameAnnotationKey, newLoggerName)(zio)
70+ } yield a
71+ }
72+
73+ /**
74+ * Append logger name aspect, by which it is possible to append a logger name to the current logger name.
75+ * The new name is appended using a dot (.) as the delimiter.
76+ *
77+ * annotation key: [[zio.logging.loggerNameAnnotationKey ]]
78+ */
79+ def appendLoggerName (value : String ): ZIOAspect [Nothing , Any , Nothing , Any , Nothing , Any ] =
80+ loggerName(currentLoggerName => currentLoggerName.fold(value)(currentLoggerName => s " $currentLoggerName. $value" ))
81+
5782 implicit final class LogAnnotationZIOSyntax [R , E , A ](private val self : ZIO [R , E , A ]) {
5883 def logAnnotate [V : Tag ](key : LogAnnotation [V ], value : V ): ZIO [R , E , A ] =
5984 self @@ key(value)
0 commit comments