Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slf4j v2 backend #639

Merged
merged 14 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
run: sbt ++${{ matrix.scala }}! testJVM8
- name: Compile additional subprojects
if: ${{ ( startsWith(matrix.scala, '2.12.') || startsWith(matrix.scala, '2.13.') ) && endsWith(matrix.java, '.11') }}
run: sbt ++${{ matrix.scala }}! examples/compile benchmarks/compile
run: sbt ++${{ matrix.scala }}! examplesCore/compile examplesJpl/compile examplesSlf4j2Bridge/compile examplesSlf4jLogback/compile examplesSlf4j2Logback/compile examplesSlf4j2Log4j/compile benchmarks/compile

ci:
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ timestamp=2022-10-28T18:40:25.54676+02:00 level=ERROR thread=zio-fiber-0 messag
at zio.logging.example.SimpleApp.run(SimpleApp.scala:14)
```

You can find the source code of examples [here](https://github.com/zio/zio-logging/tree/master/examples/src/main/scala/zio/logging/example)
You can find the source code of examples [here](https://github.com/zio/zio-logging/tree/master/examples)

## Documentation

Expand Down
112 changes: 98 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ inThisBuild(
)
)

val ZioVersion = "2.0.6"
val slf4jVersion = "1.7.36"
val slf4j2Version = "2.0.6"
val logbackVersion = "1.2.11"
val ZioVersion = "2.0.8"
val slf4jVersion = "1.7.36"
val slf4j2Version = "2.0.6"
val logbackVersion = "1.2.11"
val logback2Version = "1.4.5"

addCommandAlias("fix", "; all compile:scalafix test:scalafix; all scalafmtSbt scalafmtAll")
addCommandAlias("check", "; scalafmtSbtCheck; scalafmtCheckAll; compile:scalafix --check; test:scalafix --check")
Expand All @@ -37,7 +38,7 @@ addCommandAlias(

addCommandAlias(
"testJVM",
";coreJVM/test;slf4j/test;jpl/test;slf4jBridge/test;slf4j2Bridge/test"
";coreJVM/test;slf4j/test;slf4j2/test;jpl/test;slf4jBridge/test;slf4j2Bridge/test"
)

addCommandAlias(
Expand All @@ -55,7 +56,23 @@ lazy val root = project
.settings(
publish / skip := true
)
.aggregate(coreJVM, coreJS, slf4j, slf4jBridge, slf4j2Bridge, jpl, benchmarks, examples, docs)
.aggregate(
coreJVM,
coreJS,
slf4j,
slf4j2,
slf4jBridge,
slf4j2Bridge,
jpl,
benchmarks,
examplesCore,
examplesJpl,
examplesSlf4j2Bridge,
examplesSlf4jLogback,
examplesSlf4j2Logback,
examplesSlf4j2Log4j,
docs
)

lazy val core = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
Expand Down Expand Up @@ -98,6 +115,23 @@ lazy val slf4j = project
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)

lazy val slf4j2 = project
.in(file("slf4j2"))
.dependsOn(coreJVM)
.settings(stdSettings("zio-logging-slf4j2"))
.settings(mimaSettings(failOnProblem = true))
.settings(
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4j2Version,
"dev.zio" %%% "zio-test" % ZioVersion % Test,
"dev.zio" %%% "zio-test-sbt" % ZioVersion % Test,
"ch.qos.logback" % "logback-classic" % logback2Version % Test,
"net.logstash.logback" % "logstash-logback-encoder" % "7.2" % Test,
"org.scala-lang.modules" %% "scala-collection-compat" % "2.9.0" % Test
),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)

lazy val slf4jBridge = project
.in(file("slf4j-bridge"))
.dependsOn(coreJVM)
Expand Down Expand Up @@ -158,21 +192,71 @@ lazy val benchmarks = project
.dependsOn(coreJVM)
.enablePlugins(JmhPlugin)

lazy val examples = project
.in(file("examples"))
.dependsOn(slf4j, jpl)
.settings(stdSettings("zio-logging-examples"))
lazy val examplesCore = project
.in(file("examples/core"))
.dependsOn(coreJVM)
.settings(stdSettings("zio-logging-examples-core"))
.settings(
publish / skip := true,
libraryDependencies ++= Seq(
"dev.zio" %% "zio-metrics-connectors" % "2.0.4",
"dev.zio" %%% "zio-test" % ZioVersion % Test,
"dev.zio" %%% "zio-test-sbt" % ZioVersion % Test
)
)

lazy val examplesSlf4jLogback = project
.in(file("examples/slf4j-logback"))
.dependsOn(slf4j)
.settings(stdSettings("zio-logging-examples-slf4j-logback"))
.settings(
publish / skip := true,
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % logbackVersion,
"net.logstash.logback" % "logstash-logback-encoder" % "6.6",
"dev.zio" %% "zio-metrics-connectors" % "2.0.4",
"dev.zio" %%% "zio-test" % ZioVersion % Test,
"dev.zio" %%% "zio-test-sbt" % ZioVersion % Test
"net.logstash.logback" % "logstash-logback-encoder" % "6.6"
)
)

lazy val examplesSlf4j2Logback = project
.in(file("examples/slf4j2-logback"))
.dependsOn(slf4j2)
.settings(stdSettings("zio-logging-examples-slf4j2-logback"))
.settings(
publish / skip := true,
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % logback2Version,
"net.logstash.logback" % "logstash-logback-encoder" % "7.2"
)
)

lazy val examplesSlf4j2Log4j = project
.in(file("examples/slf4j2-log4j"))
.dependsOn(slf4j2)
.settings(stdSettings("zio-logging-examples-slf4j2-log4j"))
.settings(
publish / skip := true,
libraryDependencies ++= Seq(
"org.apache.logging.log4j" % "log4j-slf4j2-impl" % "2.19.0",
"org.apache.logging.log4j" % "log4j-core" % "2.19.0"
)
)

lazy val examplesJpl = project
.in(file("examples/jpl"))
.dependsOn(jpl)
.settings(stdSettings("zio-logging-examples-jpl"))
.settings(
publish / skip := true
)

lazy val examplesSlf4j2Bridge = project
.in(file("examples/slf4j2-bridge"))
.dependsOn(slf4j2Bridge)
.settings(stdSettings("zio-logging-examples-slf4j2-bridge"))
.settings(
publish / skip := true
)

lazy val docs = project
.in(file("zio-logging-docs"))
.settings(
Expand Down
7 changes: 5 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ There are also some optional dependencies:
// JPL integration
libraryDependencies += "dev.zio" %% "zio-logging-jpl" % "@VERSION@"

// SLF4j integration
// SLF4j v1 integration
libraryDependencies += "dev.zio" %% "zio-logging-slf4j" % "@VERSION@"

// SLF4j v2 integration
libraryDependencies += "dev.zio" %% "zio-logging-slf4j2" % "@VERSION@"

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

Expand Down Expand Up @@ -81,4 +84,4 @@ timestamp=2022-10-28T18:40:25.54676+02:00 level=ERROR thread=zio-fiber-0 messag
at zio.logging.example.SimpleApp.run(SimpleApp.scala:14)
```

You can find the source code of examples [here](https://github.com/zio/zio-logging/tree/master/examples/src/main/scala/zio/logging/example)
You can find the source code of examples [here](https://github.com/zio/zio-logging/tree/master/examples)
2 changes: 1 addition & 1 deletion docs/jpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ZIO.logInfo("Starting user operation") @@ zio.logging.loggerName("zio.logging.ex

## Examples

You can find the source code [here](https://github.com/zio/zio-logging/tree/master/examples/src/main/scala/zio/logging/example)
You can find the source code [here](https://github.com/zio/zio-logging/tree/master/examples)

### Java Platform/System logger name and annotations

Expand Down
2 changes: 1 addition & 1 deletion docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ val layer = zio.logging.logMetricsWith("log_counter", "log_level")
## Examples

You can find the source
code [here](https://github.com/zio/zio-logging/tree/master/examples/src/main/scala/zio/logging/example)
code [here](https://github.com/zio/zio-logging/tree/master/examples)

### Console logger with metrics

Expand Down
5 changes: 3 additions & 2 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const sidebars = {
'log-filter',
'console-logger',
'jpl',
'slf4j',
'slf4j1-bridge',
'slf4j2',
'slf4j1',
'slf4j2-bridge',
'slf4j1-bridge',
'metrics',
'testing'
]
Expand Down
2 changes: 1 addition & 1 deletion docs/slf4j1-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ id: slf4j1-bridge
title: "SLF4J v1 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 for SLF4J v1:
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 for SLF4J v1 (working with JDK8):

```scala
libraryDependencies += "dev.zio" %% "zio-logging-slf4j-bridge" % "@VERSION@"
Expand Down
32 changes: 16 additions & 16 deletions docs/slf4j.md → docs/slf4j1.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
id: slf4j
title: "SLF4J"
id: slf4j1
title: "SLF4J v1"
---

The Simple Logging Facade for Java ([`SLF4J`](https://www.slf4j.org/)) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j).
The Simple Logging Facade for Java ([`SLF4J v1`](https://www.slf4j.org/) - working with JDK8) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j).

In order to use this logging backend, we need to add the following line in our build.sbt file:

Expand Down Expand Up @@ -43,7 +43,7 @@ ZIO.logInfo("Confidential user operation") @@ SLF4J.logMarkerName("CONFIDENTIAL"

## Examples

You can find the source code [here](https://github.com/zio/zio-logging/tree/master/examples/src/main/scala/zio/logging/example)
You can find the source code [here](https://github.com/zio/zio-logging/tree/master/examples)


### SLF4J logger name and annotations
Expand Down Expand Up @@ -90,7 +90,7 @@ Logback configuration:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] trace_id=%X{trace_id} user_id=%X{user} %-5level %logger{36} %msg%n</Pattern>
<Pattern>%d{HH:mm:ss.SSS} [%thread] [%mdc] %-5level %logger{36} %msg%n</Pattern>
</layout>
</appender>
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
Expand All @@ -106,12 +106,12 @@ Logback configuration:

Expected Console Output:
```
13:49:14.060 [ZScheduler-Worker-2] trace_id= user_id= INFO zio.logging.example.Slf4jSimpleApp Start
13:49:14.090 [ZScheduler-Worker-12] trace_id=98cdf7b7-dc09-4935-8cbc-4a3399b67d2a user_id=3b6163f5-0677-4909-b17f-c181b53312b6 INFO zio.logging.example.UserOperation Starting user operation
13:49:14.091 [ZScheduler-Worker-8] trace_id=98cdf7b7-dc09-4935-8cbc-4a3399b67d2a user_id=75e17c12-d397-455c-89b1-4e5292d860ba INFO zio.logging.example.UserOperation Starting user operation
13:49:14.616 [ZScheduler-Worker-0] trace_id=98cdf7b7-dc09-4935-8cbc-4a3399b67d2a user_id=3b6163f5-0677-4909-b17f-c181b53312b6 INFO zio.logging.example.UserOperation Stopping user operation
13:49:14.616 [ZScheduler-Worker-10] trace_id=98cdf7b7-dc09-4935-8cbc-4a3399b67d2a user_id=75e17c12-d397-455c-89b1-4e5292d860ba INFO zio.logging.example.UserOperation Stopping user operation
13:49:14.626 [ZScheduler-Worker-0] trace_id= user_id= INFO zio.logging.example.Slf4jSimpleApp Done
12:16:21.951 [ZScheduler-Worker-8] [] INFO zio.logging.example.Slf4jSimpleApp Start
12:16:22.024 [ZScheduler-Worker-12] [user=0e3bd69c-ee62-4096-82b2-593760d3fb19, trace_id=6e956bcf-d534-4c16-9402-fb6bca13c9ab] INFO zio.logging.example.UserOperation Starting user operation
12:16:22.024 [ZScheduler-Worker-10] [user=869ed4c7-924d-4c02-ab5c-c30c1996a139, trace_id=6e956bcf-d534-4c16-9402-fb6bca13c9ab] INFO zio.logging.example.UserOperation Starting user operation
12:16:22.592 [ZScheduler-Worker-14] [user=869ed4c7-924d-4c02-ab5c-c30c1996a139, trace_id=6e956bcf-d534-4c16-9402-fb6bca13c9ab] INFO zio.logging.example.UserOperation Stopping user operation
12:16:22.592 [ZScheduler-Worker-1] [user=0e3bd69c-ee62-4096-82b2-593760d3fb19, trace_id=6e956bcf-d534-4c16-9402-fb6bca13c9ab] INFO zio.logging.example.UserOperation Stopping user operation
12:16:22.598 [ZScheduler-Worker-14] [] INFO zio.logging.example.Slf4jSimpleApp Done
```

### Custom tracing annotation
Expand Down Expand Up @@ -172,9 +172,9 @@ object CustomTracingAnnotationApp extends ZIOAppDefault {

Expected Console Output:
```
19:09:57.695 [ZScheduler-Worker-9] trace_id= user_id= INFO z.l.e.CustomTracingAnnotationApp Starting operation
19:09:57.695 [ZScheduler-Worker-9] trace_id=403fe6e9-f666-4688-a609-04813ac26892 user_id=35d36d10-4b64-48fc-bf9d-6b6b37d2f4cc INFO z.l.e.CustomTracingAnnotationApp Starting operation
19:09:58.056 [ZScheduler-Worker-8] trace_id=403fe6e9-f666-4688-a609-04813ac26892 user_id=068a35f2-2633-4404-9522-ffbfabe63730 INFO z.l.e.CustomTracingAnnotationApp Stopping operation
19:09:58.197 [ZScheduler-Worker-10] trace_id=403fe6e9-f666-4688-a609-04813ac26892 user_id=35d36d10-4b64-48fc-bf9d-6b6b37d2f4cc INFO z.l.e.CustomTracingAnnotationApp Stopping operation
19:09:58.202 [ZScheduler-Worker-13] trace_id= user_id= INFO z.l.e.CustomTracingAnnotationApp Done
15:53:20.145 [ZScheduler-Worker-9] [user=1abd8458-aefd-4780-88ec-cccd1310d4c8, trace_id=71436dd4-22d5-4e06-aaa7-f3ff7b108037] INFO z.l.e.CustomTracingAnnotationApp Starting operation
15:53:20.145 [ZScheduler-Worker-13] [user=878689e0-da30-49f8-8923-ed915c00db9c, trace_id=71436dd4-22d5-4e06-aaa7-f3ff7b108037] INFO z.l.e.CustomTracingAnnotationApp Starting operation
15:53:20.688 [ZScheduler-Worker-15] [user=1abd8458-aefd-4780-88ec-cccd1310d4c8, trace_id=71436dd4-22d5-4e06-aaa7-f3ff7b108037] INFO z.l.e.CustomTracingAnnotationApp Stopping operation
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
```
2 changes: 2 additions & 0 deletions docs/slf4j2-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ ZIO logging. Enabling both causes circular logging and makes no sense.

## Examples

You can find the source code [here](https://github.com/zio/zio-logging/tree/master/examples)

### SLF4J bridge with JSON console logger

[//]: # (TODO: make snippet type-checked using mdoc)
Expand Down
Loading