Skip to content

Commit

Permalink
slf4j bridge - docs
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon committed Jan 23, 2023
1 parent ba51a26 commit 0894243
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ libraryDependencies += "dev.zio" %% "zio-logging-jpl" % "@VERSION@"
// SLF4j integration
libraryDependencies += "dev.zio" %% "zio-logging-slf4j" % "@VERSION@"

// Using ZIO Logging for SLF4j loggers, usually third-party non-ZIO libraries
// Using ZIO Logging for SLF4j v1 loggers, usually third-party non-ZIO libraries
libraryDependencies += "dev.zio" %% "zio-logging-slf4j-bridge" % "@VERSION@"

// Using ZIO Logging for SLF4j v2 loggers, usually third-party non-ZIO libraries
libraryDependencies += "dev.zio" %% "zio-logging-slf4j2-bridge" % "@VERSION@"
```

## Example
Expand Down
13 changes: 10 additions & 3 deletions docs/slf4j-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ title: "SLF4J bridge"
---

It is possible to use `zio-logging` for SLF4J loggers, usually third-party non-ZIO libraries. To do so, import
the `zio-logging-slf4j-bridge` module:

* the `zio-logging-slf4j-bridge` module for SLF4J v1:

```scala
libraryDependencies += "dev.zio" %% "zio-logging-slf4j-bridge" % "@VERSION@"
```

* the `zio-logging-slf4j2-bridge` module for [SLF4J v2](https://www.slf4j.org/faq.html#changesInVersion200) (using JDK9+ module system ([JPMS](http://openjdk.java.net/projects/jigsaw/spec/)))

```scala
libraryDependencies += "dev.zio" %% "zio-logging-slf4j2-bridge" % "@VERSION@"
```


and use the `Slf4jBridge.initialize` layer when setting up logging:

```scala
Expand Down Expand Up @@ -67,13 +75,12 @@ ZIO logging. Enabling both causes circular logging and makes no sense.
```scala
package zio.logging.slf4j.bridge

import org.slf4j.{ Logger, LoggerFactory }
import zio.logging.{ LogFilter, LogFormat, LoggerNameExtractor, consoleJson }
import zio.{ ExitCode, LogLevel, Runtime, Scope, ZIO, ZIOAppArgs, ZIOAppDefault, ZLayer }

object Slf4jBridgeExampleApp extends ZIOAppDefault {

private val slf4jLogger: Logger = LoggerFactory.getLogger("SLF4J-LOGGER")
private val slf4jLogger = org.slf4j.LoggerFactory.getLogger("SLF4J-LOGGER")

private val loggerName = LoggerNameExtractor.annotationOrTrace(Slf4jBridge.loggerNameAnnotationKey)

Expand Down

0 comments on commit 0894243

Please sign in to comment.