Skip to content

Commit

Permalink
Merge branch 'master' into khajavi-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon authored May 14, 2024
2 parents 524fad7 + d85b460 commit 576deee
Show file tree
Hide file tree
Showing 96 changed files with 3,338 additions and 1,415 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
auto-approve:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: hmarr/[email protected]
if: github.actor == 'scala-steward' || github.actor == 'renovate[bot]'
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ jobs:
fail-fast: false
matrix:
java:
- '8'
- '11'
- '17'
scala:
- 2.12.17
- 2.13.10
- 3.2.2
- 3.3.0
steps:
- name: Install libuv
run: sudo apt-get update && sudo apt-get install -y libuv1-dev
Expand All @@ -96,7 +95,7 @@ jobs:
if: ${{ (matrix.java == '8') && (matrix.scala == '2.12.17') }}
run: 'sbt ++${{ matrix.scala }} coreJS/test slf4jBridge/test coreJVM/test slf4j/test '
- name: Test
if: ${{ (matrix.java == '17') && (matrix.scala == '3.2.2') }}
if: ${{ (matrix.java == '11') && (matrix.scala == '3.3.0') }}
run: 'sbt ++${{ matrix.scala }} slf4j/test slf4jBridge/test jpl/test slf4j2/test slf4j2Bridge/test coreJS/test coreJVM/test '
- name: Test
if: ${{ (matrix.java == '11') && (matrix.scala == '2.12.17') }}
Expand All @@ -108,10 +107,10 @@ jobs:
if: ${{ (matrix.java == '11') && (matrix.scala == '2.13.10') }}
run: 'sbt ++${{ matrix.scala }} slf4j/test slf4jBridge/test jpl/test slf4j2/test slf4j2Bridge/test coreJS/test coreJVM/test '
- name: Test
if: ${{ (matrix.java == '11') && (matrix.scala == '3.2.2') }}
if: ${{ (matrix.java == '17') && (matrix.scala == '3.3.0') }}
run: 'sbt ++${{ matrix.scala }} slf4j/test slf4jBridge/test jpl/test slf4j2/test slf4j2Bridge/test coreJS/test coreJVM/test '
- name: Test
if: ${{ (matrix.java == '8') && (matrix.scala == '3.2.2') }}
if: ${{ (matrix.java == '8') && (matrix.scala == '3.3.0') }}
run: 'sbt ++${{ matrix.scala }} coreJS/test slf4jBridge/test coreJVM/test slf4j/test '
- name: Compile additional subprojects
if: ${{ ((startsWith(matrix.scala, '2.12.')) || (startsWith(matrix.scala, '2.13.'))) && (matrix.java == '11') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
update_release_draft:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: release-drafter/release-drafter@v5
env:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.16.0
20.9.0
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.7.3"
version = "3.8.1"
runner.dialect = scala212
maxColumn = 120
align.preset = most
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In order to use this library, we need to add the following line in our `build.sb

```scala
// ZIO Logging backends
libraryDependencies += "dev.zio" %% "zio-logging" % "2.1.13"
libraryDependencies += "dev.zio" %% "zio-logging" % "2.2.2"
```

The main module contains the following features:
Expand All @@ -43,10 +43,10 @@ Other modules:

```scala
// SLF4j v1 integration
libraryDependencies += "dev.zio" %% "zio-logging-slf4j" % "2.1.13"
libraryDependencies += "dev.zio" %% "zio-logging-slf4j" % "2.2.2"

// SLF4j v2 integration
libraryDependencies += "dev.zio" %% "zio-logging-slf4j2" % "2.1.13"
libraryDependencies += "dev.zio" %% "zio-logging-slf4j2" % "2.2.2"
```
When to use this module: you are already using SLF4J logger in some other project, and you like to have same log outputs.
See SLF4J [v2](docs/slf4j2.md) or [v1](docs/slf4j1.md) section for more details.
Expand All @@ -56,10 +56,10 @@ Other modules:

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

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

When to use this module: you want to use some zio-logger implementation, but also you are using some java library which using SLF4J interface for logging.
Expand All @@ -70,7 +70,7 @@ Other modules:

```scala
// JPL integration
libraryDependencies += "dev.zio" %% "zio-logging-jpl" % "2.1.13"
libraryDependencies += "dev.zio" %% "zio-logging-jpl" % "2.2.2"
```

When to use this module: you are already using Java Platform/System Logger in some other project, and you like to have same log outputs.
Expand Down Expand Up @@ -122,11 +122,11 @@ Learn more on the [zio-logging homepage](https://zio.dev/zio-logging)!

## Contributing

For the general guidelines, see ZIO [contributor's guide](https://zio.dev/about/contributing).
For the general guidelines, see ZIO [contributor's guide](https://zio.dev/contributor-guidelines/).

## Code of Conduct

See the [Code of Conduct](https://zio.dev/about/code-of-conduct)
See the [Code of Conduct](https://zio.dev/code-of-conduct/)

## Support

Expand Down
85 changes: 50 additions & 35 deletions benchmarks/src/main/scala/zio/logging/FilterBenchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FilterBenchmarks {
val runtime = Runtime.default

val unfilteredLogging: ZLayer[Any, Nothing, Unit] =
Runtime.removeDefaultLoggers >>> consoleLogger(ConsoleLoggerConfig(LogFormat.default, LogFilter.acceptAll))
Runtime.removeDefaultLoggers >>> makeSystemOutLogger(LogFormat.default.toLogger).install

val handWrittenFilteredLogging: ZLayer[Any, Nothing, Unit] = {
val loggerNameGroup: LogGroup[Any, String] = LoggerNameExtractor.loggerNameAnnotationOrTrace.toLogGroup()
Expand All @@ -37,40 +37,45 @@ class FilterBenchmarks {
}
}
)
Runtime.removeDefaultLoggers >>> consoleLogger(ConsoleLoggerConfig(LogFormat.default, filter))
Runtime.removeDefaultLoggers >>> makeSystemOutLogger(LogFormat.default.toLogger)
.filter(filter)
.install
}

val filterConfig: LogFilter.LogLevelByNameConfig = LogFilter.LogLevelByNameConfig(
LogLevel.Debug,
"a.b.c" -> LogLevel.Info,
"a.b.d" -> LogLevel.Warning,
"e" -> LogLevel.Info,
"f.g" -> LogLevel.Error,
"f" -> LogLevel.Info
)

val filterByLogLevelAndNameLogging: ZLayer[Any, Nothing, Unit] =
Runtime.removeDefaultLoggers >>> consoleLogger(
ConsoleLoggerConfig(
LogFormat.default,
LogFilter.logLevelByName(
LogLevel.Debug,
"a.b.c" -> LogLevel.Info,
"a.b.d" -> LogLevel.Warning,
"e" -> LogLevel.Info,
"f.g" -> LogLevel.Error,
"f" -> LogLevel.Info
)
)
)
Runtime.removeDefaultLoggers >>> makeSystemOutLogger(LogFormat.default.toLogger)
.filter(filterConfig.toFilter)
.install

val cachedFilterByLogLevelAndNameLogging: ZLayer[Any, Nothing, Unit] =
Runtime.removeDefaultLoggers >>> consoleLogger(
ConsoleLoggerConfig(
LogFormat.default,
LogFilter
.logLevelByName(
LogLevel.Debug,
"a.b.c" -> LogLevel.Info,
"a.b.d" -> LogLevel.Warning,
"e" -> LogLevel.Info,
"f.g" -> LogLevel.Error,
"f" -> LogLevel.Info
)
.cached
Runtime.removeDefaultLoggers >>> makeSystemOutLogger(LogFormat.default.toLogger)
.filter(filterConfig.toFilter.cached)
.install

val reconfigurableFilterByLogLevelAndNameLogging: ZLayer[Any, Nothing, Unit] =
Runtime.removeDefaultLoggers >>> ReconfigurableLogger
.make[Any, Nothing, String, Any, ConsoleLoggerConfig](
ZIO.succeed(ConsoleLoggerConfig(LogFormat.default, filterConfig)),
(config, _) => makeSystemOutLogger(config.format.toLogger).filter(config.toFilter)
)
)
.installUnscoped[Any]

val reconfigurableCachedFilterByLogLevelAndNameLogging: ZLayer[Any, Nothing, Unit] =
Runtime.removeDefaultLoggers >>> ReconfigurableLogger
.make[Any, Nothing, String, Any, ConsoleLoggerConfig](
ZIO.succeed(ConsoleLoggerConfig(LogFormat.default, filterConfig)),
(config, _) => makeSystemOutLogger(config.format.toLogger).filter(config.toFilter.cached)
)
.installUnscoped[Any]

val names: List[String] = List(
"a",
Expand Down Expand Up @@ -108,15 +113,17 @@ class FilterBenchmarks {
}

/**
* 2022/10/28 Initial results
* 2023/12/26 Initial results
*
* jmh:run -i 3 -wi 3 -f1 -t1 .*FilterBenchmarks.*
*
* Benchmark Mode Cnt Score Error Units
* FilterBenchmarks.cachedFilterByLogLevelAndNameLog thrpt 3 16623.054 ± 15855.331 ops/s
* FilterBenchmarks.filterByLogLevelAndNameLog thrpt 3 18048.598 ± 3868.976 ops/s
* FilterBenchmarks.handWrittenFilterLog thrpt 3 16352.488 ± 2316.372 ops/s
* FilterBenchmarks.noFilteringLog thrpt 3 15104.002 ± 3857.108 ops/s
* Benchmark Mode Cnt Score Error Units
* FilterBenchmarks.cachedFilterByLogLevelAndNameLog thrpt 3 14795.547 ± 1372.850 ops/s
* FilterBenchmarks.filterByLogLevelAndNameLog thrpt 3 15093.994 ± 1230.494 ops/s
* FilterBenchmarks.handWrittenFilterLog thrpt 3 13157.888 ± 10193.287 ops/s
* FilterBenchmarks.noFilteringLog thrpt 3 11043.746 ± 230.514 ops/s
* FilterBenchmarks.reconfigurableCachedFilterByLogLevelAndNameLog thrpt 3 7532.412 ± 415.760 ops/s
* FilterBenchmarks.reconfigurableFilterByLogLevelAndNameLog thrpt 3 7482.096 ± 628.534 ops/s
*/

@Benchmark
Expand All @@ -135,4 +142,12 @@ class FilterBenchmarks {
def cachedFilterByLogLevelAndNameLog(): Unit =
testLoggingWith(cachedFilterByLogLevelAndNameLogging)

@Benchmark
def reconfigurableFilterByLogLevelAndNameLog(): Unit =
testLoggingWith(reconfigurableFilterByLogLevelAndNameLogging)

@Benchmark
def reconfigurableCachedFilterByLogLevelAndNameLog(): Unit =
testLoggingWith(reconfigurableCachedFilterByLogLevelAndNameLogging)

}
23 changes: 15 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ inThisBuild(
),
Developer("justcoon", "Peter Kotula", "[email protected]", url("https://github.com/justcoon"))
),
zioVersion := "2.0.13"
zioVersion := "2.1.1",
scala212 := "2.12.17",
scala213 := "2.13.10",
scala3 := "3.3.0",
javaPlatform := "11",
javaPlatforms := Seq("11", "17")
)
)

Expand Down Expand Up @@ -91,7 +96,8 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
.settings(enableZIO(enableStreaming = true))
.settings(
libraryDependencies ++= Seq(
"dev.zio" %%% "zio-parser" % zioParser
"dev.zio" %%% "zio-parser" % zioParser,
"dev.zio" %%% "zio-prelude" % zioPrelude
)
)
.jvmSettings(
Expand Down Expand Up @@ -131,7 +137,7 @@ lazy val slf4j2 = project
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4j2Version,
"ch.qos.logback" % "logback-classic" % logback2Version % Test,
"net.logstash.logback" % "logstash-logback-encoder" % "7.3" % Test,
"net.logstash.logback" % "logstash-logback-encoder" % "7.4" % Test,
"org.scala-lang.modules" %% "scala-collection-compat" % scalaCollectionCompatVersion % Test
)
)
Expand Down Expand Up @@ -195,8 +201,9 @@ lazy val examplesCore = project
.settings(
publish / skip := true,
libraryDependencies ++= Seq(
"dev.zio" %% "zio-metrics-connectors" % zioMetricsConnectorsVersion,
"dev.zio" %% "zio-config-typesafe" % zioConfig
"dev.zio" %% "zio-metrics-connectors-prometheus" % zioMetricsConnectorsVersion,
"dev.zio" %% "zio-http" % zioHttp,
"dev.zio" %% "zio-config-typesafe" % zioConfig
)
)

Expand All @@ -220,7 +227,7 @@ lazy val examplesSlf4j2Logback = project
publish / skip := true,
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % logback2Version,
"net.logstash.logback" % "logstash-logback-encoder" % "7.3"
"net.logstash.logback" % "logstash-logback-encoder" % "7.4"
)
)

Expand All @@ -231,8 +238,8 @@ lazy val examplesSlf4j2Log4j = project
.settings(
publish / skip := true,
libraryDependencies ++= Seq(
"org.apache.logging.log4j" % "log4j-slf4j2-impl" % "2.20.0",
"org.apache.logging.log4j" % "log4j-core" % "2.20.0"
"org.apache.logging.log4j" % "log4j-slf4j2-impl" % log4jVersion,
"org.apache.logging.log4j" % "log4j-core" % log4jVersion
)
)

Expand Down
25 changes: 25 additions & 0 deletions core/jvm/src/test/scala/zio/logging/ConsoleLoggerConfigSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ object ConsoleLoggerConfigSpec extends ZIOSpecDefault {
assertTrue(true)
}
},
test("equals config with same sources") {

// "%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %cause}" //FIXME

val logFormat =
"%highlight{%timestamp %fixed{7}{%level} [%fiberId] %name:%line %message %cause}"

val configProvider: ConfigProvider = ConfigProvider.fromMap(
Map(
"logger/format" -> logFormat,
"logger/filter/rootLevel" -> LogLevel.Info.label,
"logger/filter/mappings/zio.logging.example.LivePingService" -> LogLevel.Debug.label
),
"/"
)

import zio.prelude._
for {
c1 <- configProvider.load(ConsoleLoggerConfig.config.nested("logger"))
c2 <- configProvider.load(ConsoleLoggerConfig.config.nested("logger"))
} yield assertTrue(
c1.format == c2.format,
c1 === c2
)
},
test("fail on invalid filter config") {
val logFormat =
"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %cause}"
Expand Down
27 changes: 27 additions & 0 deletions core/jvm/src/test/scala/zio/logging/FileLoggerConfigSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ object FileLoggerConfigSpec extends ZIOSpecDefault {
assertTrue(loadedConfig.bufferedIOSize.isEmpty)
}
},
test("equals config with same sources") {

val logFormat =
"%highlight{%timestamp %fixed{7}{%level} [%fiberId] %name:%line %message %cause}"

val configProvider: ConfigProvider = ConfigProvider.fromMap(
Map(
"logger/format" -> logFormat,
"logger/path" -> "file:///tmp/test.log",
"logger/autoFlushBatchSize" -> "2",
"logger/bufferedIOSize" -> "4096",
"logger/rollingPolicy/type" -> "TimeBasedRollingPolicy",
"logger/filter/rootLevel" -> LogLevel.Info.label,
"logger/filter/mappings/zio.logging.example.LivePingService" -> LogLevel.Debug.label
),
"/"
)

import zio.prelude._
for {
c1 <- configProvider.load(ConsoleLoggerConfig.config.nested("logger"))
c2 <- configProvider.load(ConsoleLoggerConfig.config.nested("logger"))
} yield assertTrue(
c1.format == c2.format,
c1 === c2
)
},
test("fail on invalid charset and filter config") {
val logFormat =
"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %cause}"
Expand Down
Loading

0 comments on commit 576deee

Please sign in to comment.