diff --git a/core/shared/src/main/scala/zio/logging/package.scala b/core/shared/src/main/scala/zio/logging/package.scala index 4b829b33..ccc03f80 100644 --- a/core/shared/src/main/scala/zio/logging/package.scala +++ b/core/shared/src/main/scala/zio/logging/package.scala @@ -54,8 +54,6 @@ package object logging extends LoggerLayers { def loggerName(value: String): ZIOAspect[Nothing, Any, Nothing, Any, Nothing, Any] = ZIOAspect.annotated(loggerNameAnnotationKey, value) - val removeDefaultLoggers: ZLayer[Any, Nothing, Unit] = Runtime.removeDefaultLoggers - implicit final class LogAnnotationZIOSyntax[R, E, A](private val self: ZIO[R, E, A]) { def logAnnotate[V: Tag](key: LogAnnotation[V], value: V): ZIO[R, E, A] = self @@ key(value) diff --git a/docs/console-logger.md b/docs/console-logger.md index 310310ab..8debda56 100644 --- a/docs/console-logger.md +++ b/docs/console-logger.md @@ -11,7 +11,7 @@ import zio.{ ConfigProvider, Runtime } val configProvider: ConfigProvider = ??? -val logger = Runtime.removeDefaultLoggers >>> Runtime.setConfigProvider(configProvider) >>> consoleLogger(configPath = "logger") +val logger = Runtime.removeDefaultLoggers >>> Runtime.setConfigProvider(configProvider) >>> consoleLogger() ``` logger layer with given configuration: diff --git a/docs/file-logger.md b/docs/file-logger.md index 7e51274f..867ea5d5 100644 --- a/docs/file-logger.md +++ b/docs/file-logger.md @@ -11,7 +11,7 @@ import zio.{ ConfigProvider, Runtime } val configProvider: ConfigProvider = ??? -val logger = Runtime.removeDefaultLoggers >>> Runtime.setConfigProvider(configProvider) >>> fileLogger(configPath = "logger") +val logger = Runtime.removeDefaultLoggers >>> Runtime.setConfigProvider(configProvider) >>> fileLogger() ``` logger layer with given configuration: diff --git a/docs/jpl.md b/docs/jpl.md index eb116fbe..0b5ee304 100644 --- a/docs/jpl.md +++ b/docs/jpl.md @@ -91,4 +91,11 @@ Oct 28, 2022 1:47:02 PM zio.logging.backend.JPL$$anon$1 $anonfun$closeLogEntry$1 INFO: user=59c114fd-676d-4df9-a5a0-b8e132468fbf trace_id=7d3e3b84-dd3b-44ff-915a-04fb2d135e28 Stopping user operation Oct 28, 2022 1:47:02 PM zio.logging.backend.JPL$$anon$1 $anonfun$closeLogEntry$1 INFO: Done -``` \ No newline at end of file +``` + +## Feature changes + +### Version 2.2.0 + +Deprecated log annotation with key `jpl_logger_name` (`JPL.loggerNameAnnotationKey`) removed, +only common log annotation with key `logger_name` (`zio.logging.loggerNameAnnotationKey`) for logger name is supported now. diff --git a/docs/slf4j1-bridge.md b/docs/slf4j1-bridge.md index 90fc80e5..f1c9375e 100644 --- a/docs/slf4j1-bridge.md +++ b/docs/slf4j1-bridge.md @@ -53,9 +53,10 @@ ZIO logging. Enabling both causes circular logging and makes no sense. [//]: # (TODO: make snippet type-checked using mdoc) ```scala -package zio.logging.slf4j.bridge +package zio.logging.example -import zio.logging._ +import zio.logging.slf4j.bridge.Slf4jBridge +import zio.logging.{ ConsoleLoggerConfig, LogAnnotation, LogFilter, LogFormat, LoggerNameExtractor, consoleJsonLogger } import zio.{ ExitCode, LogLevel, Runtime, Scope, ZIO, ZIOAppArgs, ZIOAppDefault, ZLayer } import java.util.UUID @@ -64,23 +65,16 @@ object Slf4jBridgeExampleApp extends ZIOAppDefault { private val slf4jLogger = org.slf4j.LoggerFactory.getLogger("SLF4J-LOGGER") - private val logFilter: LogFilter[String] = LogFilter.logLevelByName( - LogLevel.Info, - "zio.logging.slf4j" -> LogLevel.Debug, - "SLF4J-LOGGER" -> LogLevel.Warning - ) + private val logFormat = LogFormat.label( + "name", + LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() + ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( + LogAnnotation.TraceId + ) + LogFormat.default override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] = Runtime.removeDefaultLoggers >>> consoleJsonLogger( - ConsoleLoggerConfig( - LogFormat.label( - "name", - LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() - ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( - LogAnnotation.TraceId - ) + LogFormat.default, - logFilter - ) + ConsoleLoggerConfig(logFormat, logFilterConfig) ) >+> Slf4jBridge.initialize private val uuids = List.fill(2)(UUID.randomUUID()) @@ -145,3 +139,10 @@ val logFilter: LogFilter[String] = LogFilter.logLevelByGroup( "SLF4J-LOGGER" -> LogLevel.Warning ) ``` + +### Version 2.2.0 + +Deprecated log annotation with key `slf4j_logger_name` (`Slf4jBridge.loggerNameAnnotationKey`) removed, +only common log annotation with key `logger_name` (`zio.logging.loggerNameAnnotationKey`) for logger name is supported now. + + diff --git a/docs/slf4j1.md b/docs/slf4j1.md index 6a271264..8db60dd6 100644 --- a/docs/slf4j1.md +++ b/docs/slf4j1.md @@ -185,3 +185,11 @@ Expected Console Output: 15:53:20.688 [ZScheduler-Worker-11] [user=878689e0-da30-49f8-8923-ed915c00db9c, trace_id=71436dd4-22d5-4e06-aaa7-f3ff7b108037] INFO z.l.e.CustomTracingAnnotationApp Stopping operation 15:53:20.691 [ZScheduler-Worker-15] [] INFO z.l.e.CustomTracingAnnotationApp Done ``` + +## Feature changes + +### Version 2.2.0 + +Deprecated log annotation with key `slf4j_logger_name` (`SLF4J.loggerNameAnnotationKey`) removed, +only common log annotation with key `logger_name` (`zio.logging.loggerNameAnnotationKey`) for logger name is supported now. + diff --git a/docs/slf4j2-bridge.md b/docs/slf4j2-bridge.md index 5b4f08b9..ec3e097b 100644 --- a/docs/slf4j2-bridge.md +++ b/docs/slf4j2-bridge.md @@ -33,11 +33,13 @@ may be used to get logger name from log annotation or ZIO Trace. This logger name extractor is used by default in log filter, which applying log filtering by defined logger name and level: ```scala -val logFilter: LogFilter[String] = LogFilter.logLevelByName( +val logFilterConfig = LogFilter.LogLevelByNameConfig( LogLevel.Info, "zio.logging.slf4j" -> LogLevel.Debug, "SLF4J-LOGGER" -> LogLevel.Warning ) + +val logFilter: LogFilter[String] = logFilterConfig.toFilter ```
@@ -65,9 +67,10 @@ You can find the source code [here](https://github.com/zio/zio-logging/tree/mast [//]: # (TODO: make snippet type-checked using mdoc) ```scala -package zio.logging.slf4j.bridge +package zio.logging.example -import zio.logging._ +import zio.logging.slf4j.bridge.Slf4jBridge +import zio.logging.{ ConsoleLoggerConfig, LogAnnotation, LogFilter, LogFormat, LoggerNameExtractor, consoleJsonLogger } import zio.{ ExitCode, LogLevel, Runtime, Scope, ZIO, ZIOAppArgs, ZIOAppDefault, ZLayer } import java.util.UUID @@ -76,23 +79,22 @@ object Slf4jBridgeExampleApp extends ZIOAppDefault { private val slf4jLogger = org.slf4j.LoggerFactory.getLogger("SLF4J-LOGGER") - private val logFilter: LogFilter[String] = LogFilter.logLevelByName( + private val logFilterConfig = LogFilter.LogLevelByNameConfig( LogLevel.Info, "zio.logging.slf4j" -> LogLevel.Debug, "SLF4J-LOGGER" -> LogLevel.Warning ) + private val logFormat = LogFormat.label( + "name", + LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() + ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( + LogAnnotation.TraceId + ) + LogFormat.default + override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] = Runtime.removeDefaultLoggers >>> consoleJsonLogger( - ConsoleLoggerConfig( - LogFormat.label( - "name", - LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() - ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( - LogAnnotation.TraceId - ) + LogFormat.default, - logFilter - ) + ConsoleLoggerConfig(logFormat, logFilterConfig) ) >+> Slf4jBridge.initialize private val uuids = List.fill(2)(UUID.randomUUID()) diff --git a/examples/slf4j2-bridge/src/main/scala/zio/logging/example/Slf4jBridgeExampleApp.scala b/examples/slf4j2-bridge/src/main/scala/zio/logging/example/Slf4jBridgeExampleApp.scala index 1c03d6bb..69de5ad2 100644 --- a/examples/slf4j2-bridge/src/main/scala/zio/logging/example/Slf4jBridgeExampleApp.scala +++ b/examples/slf4j2-bridge/src/main/scala/zio/logging/example/Slf4jBridgeExampleApp.scala @@ -31,17 +31,16 @@ object Slf4jBridgeExampleApp extends ZIOAppDefault { "SLF4J-LOGGER" -> LogLevel.Warning ) + private val logFormat = LogFormat.label( + "name", + LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() + ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( + LogAnnotation.TraceId + ) + LogFormat.default + override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] = Runtime.removeDefaultLoggers >>> consoleJsonLogger( - ConsoleLoggerConfig( - LogFormat.label( - "name", - LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() - ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( - LogAnnotation.TraceId - ) + LogFormat.default, - logFilterConfig - ) + ConsoleLoggerConfig(logFormat, logFilterConfig) ) >+> Slf4jBridge.initialize private val uuids = List.fill(2)(UUID.randomUUID()) diff --git a/slf4j-bridge/src/test/scala/zio/logging/slf4j/bridge/Slf4jBridgeExampleApp.scala b/slf4j-bridge/src/test/scala/zio/logging/slf4j/bridge/Slf4jBridgeExampleApp.scala index 2f5b1198..489d8b44 100644 --- a/slf4j-bridge/src/test/scala/zio/logging/slf4j/bridge/Slf4jBridgeExampleApp.scala +++ b/slf4j-bridge/src/test/scala/zio/logging/slf4j/bridge/Slf4jBridgeExampleApp.scala @@ -15,17 +15,16 @@ object Slf4jBridgeExampleApp extends ZIOAppDefault { "SLF4J-LOGGER" -> LogLevel.Warning ) + private val logFormat = LogFormat.label( + "name", + LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() + ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( + LogAnnotation.TraceId + ) + LogFormat.default + override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] = Runtime.removeDefaultLoggers >>> consoleJsonLogger( - ConsoleLoggerConfig( - LogFormat.label( - "name", - LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() - ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( - LogAnnotation.TraceId - ) + LogFormat.default, - logFilterConfig - ) + ConsoleLoggerConfig(logFormat, logFilterConfig) ) >+> Slf4jBridge.initialize private val uuids = List.fill(2)(UUID.randomUUID()) diff --git a/slf4j2-bridge/src/test/scala/zio/logging/slf4j/bridge/Slf4jBridgeExampleApp.scala b/slf4j2-bridge/src/test/scala/zio/logging/slf4j/bridge/Slf4jBridgeExampleApp.scala index 928cd06b..06c7ff16 100644 --- a/slf4j2-bridge/src/test/scala/zio/logging/slf4j/bridge/Slf4jBridgeExampleApp.scala +++ b/slf4j2-bridge/src/test/scala/zio/logging/slf4j/bridge/Slf4jBridgeExampleApp.scala @@ -15,17 +15,16 @@ object Slf4jBridgeExampleApp extends ZIOAppDefault { "SLF4J-LOGGER" -> LogLevel.Warning ) + private val logFormat = LogFormat.label( + "name", + LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() + ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( + LogAnnotation.TraceId + ) + LogFormat.default + override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] = Runtime.removeDefaultLoggers >>> consoleJsonLogger( - ConsoleLoggerConfig( - LogFormat.label( - "name", - LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogFormat() - ) + LogFormat.logAnnotation(LogAnnotation.UserId) + LogFormat.logAnnotation( - LogAnnotation.TraceId - ) + LogFormat.default, - logFilterConfig - ) + ConsoleLoggerConfig(logFormat, logFilterConfig) ) >+> Slf4jBridge.initialize private val uuids = List.fill(2)(UUID.randomUUID())