Skip to content

Commit

Permalink
doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon committed Oct 28, 2023
1 parent 2549bf3 commit 25602c1
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 61 deletions.
2 changes: 0 additions & 2 deletions core/shared/src/main/scala/zio/logging/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/console-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/file-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion docs/jpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```

## 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.
33 changes: 17 additions & 16 deletions docs/slf4j1-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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.


8 changes: 8 additions & 0 deletions docs/slf4j1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

28 changes: 15 additions & 13 deletions docs/slf4j2-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
<br/>

Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 25602c1

Please sign in to comment.