diff --git a/docs/reconfigurable-logger.md b/docs/reconfigurable-logger.md
index 2aa797a0..d78da4cf 100644
--- a/docs/reconfigurable-logger.md
+++ b/docs/reconfigurable-logger.md
@@ -5,7 +5,7 @@ title: "Reconfigurable Logger"
`ReconfigurableLogger` is adding support for updating logger configuration in application runtime.
-logger layer with configuration from config provider (example with [Console Logger)](console-logger.md)):
+logger layer with configuration from `ConfigProvider` (example with [Console Logger)](console-logger.md)):
```scala
@@ -25,16 +25,18 @@ val logger = Runtime.removeDefaultLoggers >>> Runtime.setConfigProvider(configPr
`ReconfigurableLogger`, based on given `Schedule` and load configuration function, will recreate logger if configuration changed.
+**NOTE:** consider if you need this feature in your application, as there may be some performance impacts (see [benchmarks](https://github.com/zio/zio-logging/blob/master/benchmarks/src/main/scala/zio/logging/FilterBenchmarks.scala)).
+
## Examples
You can find the source code [here](https://github.com/zio/zio-logging/tree/master/examples)
-### Colorful Console Logger With Reconfiguration In Runtime
+### Console Logger With Re-configuration From Configuration File In Runtime
[//]: # (TODO: make snippet type-checked using mdoc)
-By default, root level configuration is `INFO`, when root level configuration is changed to `DEBUG`, other logger messages should be in output.
+Example of application where logger configuration is updated at runtime when logger configuration file is changed.
Configuration:
@@ -42,7 +44,10 @@ Configuration:
logger {
format = "%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"
filter {
- rootLevel = "DEBUG"
+ rootLevel = "INFO"
+ mappings {
+ "zio.logging.example" = "DEBUG"
+ }
}
}
```
@@ -77,8 +82,7 @@ object LoggerReconfigureApp extends ZIOAppDefault {
for {
config <- ZIO.succeed(ConfigFactory.load("logger.conf"))
_ <- Console.printLine(config.getConfig("logger")).orDie
- loggerConfig <-
- TypesafeConfigProvider.fromTypesafeConfig(config).nested("logger").load(ConsoleLoggerConfig.config)
+ loggerConfig <- ConsoleLoggerConfig.load().withConfigProvider(TypesafeConfigProvider.fromTypesafeConfig(config))
} yield loggerConfig
)
@@ -107,31 +111,148 @@ object LoggerReconfigureApp extends ZIOAppDefault {
}
```
-Expected console output:
+When configuration for `logger/filter/mappings/zio.logging.example` change from `DEBUG` to `WARN`:
+
+```
+Config(SimpleConfigObject({"filter":{"mappings":{"zio.logging.example":"DEBUG"},"rootLevel":"INFO"},"format":"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"}))
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-5] zio.logging.example.LoggerReconfigureApp:51 Start trace_id=87ead38c-8b42-43ea-9905-039d0263026d
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-36] zio.logging.example.LoggerReconfigureApp:55 Starting operation trace_id=87ead38c-8b42-43ea-9905-039d0263026d user_id=dfa05247-ec27-46f7-a4e0-bb86f2d501e9
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-37] zio.logging.example.LoggerReconfigureApp:55 Starting operation trace_id=87ead38c-8b42-43ea-9905-039d0263026d user_id=19693c77-0896-4fae-a830-67d5fe370b05
+2023-12-26T10:10:26+0100 ERROR [zio-fiber-36] zio.logging.example.LoggerReconfigureApp:57 Error operation trace_id=87ead38c-8b42-43ea-9905-039d0263026d user_id=dfa05247-ec27-46f7-a4e0-bb86f2d501e9
+2023-12-26T10:10:26+0100 ERROR [zio-fiber-37] zio.logging.example.LoggerReconfigureApp:57 Error operation trace_id=87ead38c-8b42-43ea-9905-039d0263026d user_id=19693c77-0896-4fae-a830-67d5fe370b05
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-36] zio.logging.example.LoggerReconfigureApp:58 Stopping operation trace_id=87ead38c-8b42-43ea-9905-039d0263026d user_id=dfa05247-ec27-46f7-a4e0-bb86f2d501e9
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-37] zio.logging.example.LoggerReconfigureApp:58 Stopping operation trace_id=87ead38c-8b42-43ea-9905-039d0263026d user_id=19693c77-0896-4fae-a830-67d5fe370b05
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-5] zio.logging.example.LoggerReconfigureApp:61 Done trace_id=87ead38c-8b42-43ea-9905-039d0263026d
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-5] zio.logging.example.LoggerReconfigureApp:51 Start trace_id=c6d4c770-8db1-4ea8-91eb-548c6a99a90c
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-39] zio.logging.example.LoggerReconfigureApp:55 Starting operation trace_id=c6d4c770-8db1-4ea8-91eb-548c6a99a90c user_id=a62a153f-6a91-491e-8c97-bab94186f0a2
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-38] zio.logging.example.LoggerReconfigureApp:55 Starting operation trace_id=c6d4c770-8db1-4ea8-91eb-548c6a99a90c user_id=8eeb6442-80a9-40e5-b97d-a12876702a65
+2023-12-26T10:10:26+0100 ERROR [zio-fiber-39] zio.logging.example.LoggerReconfigureApp:57 Error operation trace_id=c6d4c770-8db1-4ea8-91eb-548c6a99a90c user_id=a62a153f-6a91-491e-8c97-bab94186f0a2
+2023-12-26T10:10:26+0100 ERROR [zio-fiber-38] zio.logging.example.LoggerReconfigureApp:57 Error operation trace_id=c6d4c770-8db1-4ea8-91eb-548c6a99a90c user_id=8eeb6442-80a9-40e5-b97d-a12876702a65
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-39] zio.logging.example.LoggerReconfigureApp:58 Stopping operation trace_id=c6d4c770-8db1-4ea8-91eb-548c6a99a90c user_id=a62a153f-6a91-491e-8c97-bab94186f0a2
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-38] zio.logging.example.LoggerReconfigureApp:58 Stopping operation trace_id=c6d4c770-8db1-4ea8-91eb-548c6a99a90c user_id=8eeb6442-80a9-40e5-b97d-a12876702a65
+2023-12-26T10:10:26+0100 DEBUG [zio-fiber-5] zio.logging.example.LoggerReconfigureApp:61 Done trace_id=c6d4c770-8db1-4ea8-91eb-548c6a99a90c
+Config(SimpleConfigObject({"filter":{"mappings":{"zio.logging.example":"WARN"},"rootLevel":"INFO"},"format":"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"}))
+2023-12-26T10:10:27+0100 ERROR [zio-fiber-40] zio.logging.example.LoggerReconfigureApp:57 Error operation trace_id=e2d8bbb4-5ad0-4952-b035-03da7689ab56 user_id=0f6452da-3f7e-40ff-b8b4-6b4c731903fb
+2023-12-26T10:10:27+0100 ERROR [zio-fiber-41] zio.logging.example.LoggerReconfigureApp:57 Error operation trace_id=e2d8bbb4-5ad0-4952-b035-03da7689ab56 user_id=c4a86b38-90d7-4bb6-9f49-73bc5701e1ef
+```
+
+### Console Logger With Configuration By Http APIs
+
+[//]: # (TODO: make snippet type-checked using mdoc)
+
+Example of application where logger configuration can be changed by Http APIs.
+
+Logger configurations APIs:
+* get logger configurations
+ ```bash
+ curl -u "admin:admin" 'http://localhost:8080/example/logger'
+ ```
+* get `root` logger configuration
+ ```bash
+ curl -u "admin:admin" 'http://localhost:8080/example/logger/root'
+ ```
+* set `root` logger configuration
+ ```bash
+ curl -u "admin:admin" --location --request PUT 'http://localhost:8080/example/logger/root' --header 'Content-Type: application/json' --data-raw '"WARN"'
+ ```
+* get `zio.logging.example` logger configuration
+ ```bash
+ curl -u "admin:admin" --location --request PUT 'http://localhost:8080/example/logger/zio.logging.example' --header 'Content-Type: application/json' --data-raw '"WARN"'
+ ```
+
+Configuration:
+
+```
+logger {
+ format = "%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"
+ filter {
+ rootLevel = "INFO"
+ mappings {
+ "zio.logging.example" = "DEBUG"
+ }
+ }
+}
+```
+
+Application:
+
+```scala
+package zio.logging.example
+
+import com.typesafe.config.ConfigFactory
+import zio.config.typesafe.TypesafeConfigProvider
+import zio.http._
+import zio.logging.api.http.ApiHandlers
+import zio.logging.{ ConfigurableLogger, ConsoleLoggerConfig, LogAnnotation, LoggerConfigurer, makeConsoleLogger }
+import zio.{ ExitCode, Runtime, Scope, ZIO, ZIOAppDefault, _ }
+
+import java.util.UUID
+
+object ConfigurableLoggerApp extends ZIOAppDefault {
+
+ def configurableLogger() =
+ ConsoleLoggerConfig
+ .load()
+ .flatMap { config =>
+ makeConsoleLogger(config).map { logger =>
+ ConfigurableLogger.make(logger, config.filter)
+ }
+ }
+ .install
+
+ val configProvider: ConfigProvider = TypesafeConfigProvider.fromTypesafeConfig(ConfigFactory.load("logger.conf"))
+
+ override val bootstrap: ZLayer[Any, Config.Error, Unit] =
+ Runtime.removeDefaultLoggers >>> Runtime.setConfigProvider(configProvider) >>> configurableLogger()
+
+ def exec(): ZIO[Any, Nothing, Unit] =
+ for {
+ ok <- Random.nextBoolean
+ traceId <- ZIO.succeed(UUID.randomUUID())
+ _ <- ZIO.logDebug("Start") @@ LogAnnotation.TraceId(traceId)
+ userIds <- ZIO.succeed(List.fill(2)(UUID.randomUUID().toString))
+ _ <- ZIO.foreachPar(userIds) { userId =>
+ {
+ ZIO.logDebug("Starting operation") *>
+ ZIO.logInfo("OK operation").when(ok) *>
+ ZIO.logError("Error operation").when(!ok) *>
+ ZIO.logDebug("Stopping operation")
+ } @@ LogAnnotation.UserId(userId)
+ } @@ LogAnnotation.TraceId(traceId)
+ _ <- ZIO.logDebug("Done") @@ LogAnnotation.TraceId(traceId)
+ } yield ()
+
+ val httpApp: HttpApp[LoggerConfigurer] =
+ ApiHandlers.routes("example" :: Nil).toHttpApp @@ Middleware.basicAuth("admin", "admin")
+
+ override def run: ZIO[Scope, Any, ExitCode] =
+ (for {
+ _ <- Server.serve(httpApp).fork
+ _ <- exec().repeat(Schedule.fixed(500.millis))
+ } yield ExitCode.success).provide(LoggerConfigurer.layer ++ Server.default)
+
+}
+```
+
+**NOTE:** `ConfigurableLogger` and `ApiHandlers` are currently implemented in examples,
+it will be considered in the future, if they will be moved to official `zio-logging` implementation
+(once there will be official stable `zio-http` release).
+If you like to use them in your app, you can copy them.
+
+When configuration for `logger/filter/mappings/zio.logging.example` change from `DEBUG` to `WARN`:
+
+```bash
+curl -u "admin:admin" --location --request PUT 'http://localhost:8080/example/logger/zio.logging.example' --header 'Content-Type: application/json' --data-raw '"WARN"'
+```
```
-Config(SimpleConfigObject({"filter":{"mappings":{},"rootLevel":"INFO"},"format":"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"}))
-2023-12-25T11:11:27+0100 ERROR [zio-fiber-106] zio.logging.example.LoggerReconfigureApp:58 Error operation trace_id=18788cfd-5efe-488b-8549-c69f374110ea user_id=b31bb7a0-f8d1-4d7d-8215-1c980ec0e986
-2023-12-25T11:11:27+0100 ERROR [zio-fiber-107] zio.logging.example.LoggerReconfigureApp:58 Error operation trace_id=18788cfd-5efe-488b-8549-c69f374110ea user_id=2c390abc-17a7-413d-9d4a-668215727fbd
-Config(SimpleConfigObject({"filter":{"mappings":{},"rootLevel":"INFO"},"format":"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"}))
-2023-12-25T11:11:28+0100 ERROR [zio-fiber-108] zio.logging.example.LoggerReconfigureApp:58 Error operation trace_id=865905f4-9548-44b6-bd60-9b2d30da95f4 user_id=6abecac0-b867-4f50-a699-c344d2548b79
-2023-12-25T11:11:28+0100 ERROR [zio-fiber-109] zio.logging.example.LoggerReconfigureApp:58 Error operation trace_id=865905f4-9548-44b6-bd60-9b2d30da95f4 user_id=b7f73c21-2dc6-4707-8bdd-96cfd7500e26
-Config(SimpleConfigObject({"filter":{"mappings":{},"rootLevel":"DEBUG"},"format":"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"}))
-2023-12-25T11:11:28+0100 DEBUG [zio-fiber-5] zio.logging.example.LoggerReconfigureApp:52 Start trace_id=44ac195b-9e17-42d8-b8ff-264a52275855
-2023-12-25T11:11:28+0100 DEBUG [zio-fiber-110] zio.logging.example.LoggerReconfigureApp:56 Starting operation trace_id=44ac195b-9e17-42d8-b8ff-264a52275855 user_id=a976cb5b-d035-488f-9664-3761a07fb2d9
-2023-12-25T11:11:28+0100 DEBUG [zio-fiber-111] zio.logging.example.LoggerReconfigureApp:56 Starting operation trace_id=44ac195b-9e17-42d8-b8ff-264a52275855 user_id=ed23b03a-00e5-4495-8a0d-092eee0a7479
-2023-12-25T11:11:28+0100 INFO [zio-fiber-110] zio.logging.example.LoggerReconfigureApp:57 OK operation trace_id=44ac195b-9e17-42d8-b8ff-264a52275855 user_id=a976cb5b-d035-488f-9664-3761a07fb2d9
-2023-12-25T11:11:28+0100 INFO [zio-fiber-111] zio.logging.example.LoggerReconfigureApp:57 OK operation trace_id=44ac195b-9e17-42d8-b8ff-264a52275855 user_id=ed23b03a-00e5-4495-8a0d-092eee0a7479
-2023-12-25T11:11:28+0100 DEBUG [zio-fiber-111] zio.logging.example.LoggerReconfigureApp:59 Stopping operation trace_id=44ac195b-9e17-42d8-b8ff-264a52275855 user_id=ed23b03a-00e5-4495-8a0d-092eee0a7479
-2023-12-25T11:11:28+0100 DEBUG [zio-fiber-110] zio.logging.example.LoggerReconfigureApp:59 Stopping operation trace_id=44ac195b-9e17-42d8-b8ff-264a52275855 user_id=a976cb5b-d035-488f-9664-3761a07fb2d9
-2023-12-25T11:11:28+0100 DEBUG [zio-fiber-5] zio.logging.example.LoggerReconfigureApp:62 Done trace_id=44ac195b-9e17-42d8-b8ff-264a52275855
-Config(SimpleConfigObject({"filter":{"mappings":{},"rootLevel":"DEBUG"},"format":"%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"}))
-2023-12-25T11:11:29+0100 DEBUG [zio-fiber-5] zio.logging.example.LoggerReconfigureApp:52 Start trace_id=f613ff34-8d8a-49e8-b58c-5fa954f3bc79
-2023-12-25T11:11:29+0100 DEBUG [zio-fiber-113] zio.logging.example.LoggerReconfigureApp:56 Starting operation trace_id=f613ff34-8d8a-49e8-b58c-5fa954f3bc79 user_id=0c513b80-3fc6-4aa9-a805-11e658805296
-2023-12-25T11:11:29+0100 DEBUG [zio-fiber-112] zio.logging.example.LoggerReconfigureApp:56 Starting operation trace_id=f613ff34-8d8a-49e8-b58c-5fa954f3bc79 user_id=aa296f97-6503-4633-ac78-16094f00ceca
-2023-12-25T11:11:29+0100 ERROR [zio-fiber-113] zio.logging.example.LoggerReconfigureApp:58 Error operation trace_id=f613ff34-8d8a-49e8-b58c-5fa954f3bc79 user_id=0c513b80-3fc6-4aa9-a805-11e658805296
-2023-12-25T11:11:29+0100 ERROR [zio-fiber-112] zio.logging.example.LoggerReconfigureApp:58 Error operation trace_id=f613ff34-8d8a-49e8-b58c-5fa954f3bc79 user_id=aa296f97-6503-4633-ac78-16094f00ceca
-2023-12-25T11:11:29+0100 DEBUG [zio-fiber-113] zio.logging.example.LoggerReconfigureApp:59 Stopping operation trace_id=f613ff34-8d8a-49e8-b58c-5fa954f3bc79 user_id=0c513b80-3fc6-4aa9-a805-11e658805296
-2023-12-25T11:11:29+0100 DEBUG [zio-fiber-112] zio.logging.example.LoggerReconfigureApp:59 Stopping operation trace_id=f613ff34-8d8a-49e8-b58c-5fa954f3bc79 user_id=aa296f97-6503-4633-ac78-16094f00ceca
-2023-12-25T11:11:29+0100 DEBUG [zio-fiber-5] zio.logging.example.LoggerReconfigureApp:62 Done trace_id=f613ff34-8d8a-49e8-b58c-5fa954f3bc79
+2023-12-26T10:49:27+0100 DEBUG [zio-fiber-73] zio.logging.example.ConfigurableLoggerApp:62 Starting operation trace_id=dcf30228-dc00-4c1f-ab94-20c9f8116045 user_id=5d35778f-78ff-48a8-aa6a-73114ec719b5
+2023-12-26T10:49:27+0100 DEBUG [zio-fiber-72] zio.logging.example.ConfigurableLoggerApp:62 Starting operation trace_id=dcf30228-dc00-4c1f-ab94-20c9f8116045 user_id=9e17bd97-aa18-4b09-a423-9de28241a20b
+2023-12-26T10:49:27+0100 INFO [zio-fiber-73] zio.logging.example.ConfigurableLoggerApp:63 OK operation trace_id=dcf30228-dc00-4c1f-ab94-20c9f8116045 user_id=5d35778f-78ff-48a8-aa6a-73114ec719b5
+2023-12-26T10:49:27+0100 INFO [zio-fiber-72] zio.logging.example.ConfigurableLoggerApp:63 OK operation trace_id=dcf30228-dc00-4c1f-ab94-20c9f8116045 user_id=9e17bd97-aa18-4b09-a423-9de28241a20b
+2023-12-26T10:49:27+0100 DEBUG [zio-fiber-73] zio.logging.example.ConfigurableLoggerApp:65 Stopping operation trace_id=dcf30228-dc00-4c1f-ab94-20c9f8116045 user_id=5d35778f-78ff-48a8-aa6a-73114ec719b5
+2023-12-26T10:49:27+0100 DEBUG [zio-fiber-72] zio.logging.example.ConfigurableLoggerApp:65 Stopping operation trace_id=dcf30228-dc00-4c1f-ab94-20c9f8116045 user_id=9e17bd97-aa18-4b09-a423-9de28241a20b
+2023-12-26T10:49:27+0100 DEBUG [zio-fiber-4] zio.logging.example.ConfigurableLoggerApp:68 Done trace_id=dcf30228-dc00-4c1f-ab94-20c9f8116045
+2023-12-26T10:49:28+0100 ERROR [zio-fiber-77] zio.logging.example.ConfigurableLoggerApp:64 Error operation trace_id=7da8765e-2e27-42c6-8834-16d15d21c72c user_id=4395d188-5971-4839-a721-278d07a2881b
+2023-12-26T10:49:28+0100 ERROR [zio-fiber-78] zio.logging.example.ConfigurableLoggerApp:64 Error operation trace_id=7da8765e-2e27-42c6-8834-16d15d21c72c user_id=27af6873-2f7b-4b9a-ad2b-6bd12479cace
```
diff --git a/docs/slf4j1-bridge.md b/docs/slf4j1-bridge.md
index f1c9375e..df921d35 100644
--- a/docs/slf4j1-bridge.md
+++ b/docs/slf4j1-bridge.md
@@ -42,7 +42,7 @@ val logger = Runtime.removeDefaultLoggers >>> consoleJsonLogger() >+> Slf4jBridg
```
-**NOTE** You should either use `zio-logging-slf4j` to send all ZIO logs to an SLF4j provider (such as logback, log4j etc) OR `zio-logging-slf4j-bridge` to send all SLF4j logs to
+**NOTE:** You should either use `zio-logging-slf4j` to send all ZIO logs to an SLF4j provider (such as logback, log4j etc) OR `zio-logging-slf4j-bridge` to send all SLF4j logs to
ZIO logging. Enabling both causes circular logging and makes no sense.
diff --git a/docs/slf4j2-bridge.md b/docs/slf4j2-bridge.md
index ec3e097b..7ddddf5c 100644
--- a/docs/slf4j2-bridge.md
+++ b/docs/slf4j2-bridge.md
@@ -54,7 +54,7 @@ val logger = Runtime.removeDefaultLoggers >>> consoleJsonLogger() >+> Slf4jBridg
-**NOTE** You should either use `zio-logging-slf4j` to send all ZIO logs to an SLF4j provider (such as logback, log4j etc) OR `zio-logging-slf4j-bridge` to send all SLF4j logs to
+**NOTE:** You should either use `zio-logging-slf4j` to send all ZIO logs to an SLF4j provider (such as logback, log4j etc) OR `zio-logging-slf4j-bridge` to send all SLF4j logs to
ZIO logging. Enabling both causes circular logging and makes no sense.
diff --git a/examples/core/src/main/resources/logger.conf b/examples/core/src/main/resources/logger.conf
index 5c65f06c..0db7b21f 100644
--- a/examples/core/src/main/resources/logger.conf
+++ b/examples/core/src/main/resources/logger.conf
@@ -3,6 +3,7 @@ logger {
filter {
rootLevel = "INFO"
mappings {
+ "zio.logging.example" = "DEBUG"
}
}
}
\ No newline at end of file
diff --git a/examples/core/src/main/scala/zio/logging/api/http/ApiEndpoints.scala b/examples/core/src/main/scala/zio/logging/api/http/ApiEndpoints.scala
index feb6f12c..cc22f605 100644
--- a/examples/core/src/main/scala/zio/logging/api/http/ApiEndpoints.scala
+++ b/examples/core/src/main/scala/zio/logging/api/http/ApiEndpoints.scala
@@ -18,9 +18,10 @@ package zio.logging.api.http
import zio._
import zio.http._
import zio.http.codec.PathCodec.{ literal, string }
-import zio.http.codec.{ Doc, HttpCodec, PathCodec }
+import zio.http.codec.{ HttpCodec, PathCodec }
import zio.http.endpoint.EndpointMiddleware.None
import zio.http.endpoint._
+import zio.http.endpoint.openapi.{ OpenAPI, OpenAPIGen }
import zio.logging.api.http.ApiDomain.Error
object ApiEndpoints {
@@ -58,6 +59,12 @@ object ApiEndpoints {
.out[ApiDomain.LoggerConfig]
.outError[ApiDomain.Error.Internal](Status.InternalServerError)
- def doc(rootPath: Seq[String] = Seq.empty): Doc =
- getLoggerConfigs(rootPath).doc + getLoggerConfig(rootPath).doc + setLoggerConfig(rootPath).doc
+ def openAPI(rootPath: Seq[String] = Seq.empty): OpenAPI =
+ OpenAPIGen.fromEndpoints(
+ title = "Logger Configurations API",
+ version = "1.0",
+ getLoggerConfigs(rootPath),
+ getLoggerConfig(rootPath),
+ setLoggerConfig(rootPath)
+ )
}
diff --git a/examples/core/src/main/scala/zio/logging/example/ConfigurableLoggerApp.scala b/examples/core/src/main/scala/zio/logging/example/ConfigurableLoggerApp.scala
index 200fe572..0fb86fb1 100644
--- a/examples/core/src/main/scala/zio/logging/example/ConfigurableLoggerApp.scala
+++ b/examples/core/src/main/scala/zio/logging/example/ConfigurableLoggerApp.scala
@@ -15,16 +15,11 @@
*/
package zio.logging.example
+import com.typesafe.config.ConfigFactory
+import zio.config.typesafe.TypesafeConfigProvider
import zio.http._
import zio.logging.api.http.ApiHandlers
-import zio.logging.{
- ConfigurableLogger,
- ConsoleLoggerConfig,
- LogAnnotation,
- LoggerConfigurer,
- loggerConfigPath,
- makeConsoleLogger
-}
+import zio.logging.{ ConfigurableLogger, ConsoleLoggerConfig, LogAnnotation, LoggerConfigurer, makeConsoleLogger }
import zio.{ ExitCode, Runtime, Scope, ZIO, ZIOAppDefault, _ }
import java.util.UUID
@@ -41,9 +36,9 @@ import java.util.UUID
*/
object ConfigurableLoggerApp extends ZIOAppDefault {
- def configurableLogger(configPath: NonEmptyChunk[String] = loggerConfigPath) =
+ def configurableLogger() =
ConsoleLoggerConfig
- .load(configPath)
+ .load()
.flatMap { config =>
makeConsoleLogger(config).map { logger =>
ConfigurableLogger.make(logger, config.filter)
@@ -51,17 +46,7 @@ object ConfigurableLoggerApp extends ZIOAppDefault {
}
.install
- val logFormat =
- "%highlight{%timestamp{yyyy-MM-dd'T'HH:mm:ssZ} %fixed{7}{%level} [%fiberId] %name:%line %message %kv{trace_id} %kv{user_id} %cause}"
-
- val configProvider: ConfigProvider = ConfigProvider.fromMap(
- Map(
- "logger/format" -> logFormat,
- "logger/filter/rootLevel" -> LogLevel.Info.label,
- "logger/filter/mappings/zio.logging.example" -> LogLevel.Debug.label
- ),
- "/"
- )
+ val configProvider: ConfigProvider = TypesafeConfigProvider.fromTypesafeConfig(ConfigFactory.load("logger.conf"))
override val bootstrap: ZLayer[Any, Config.Error, Unit] =
Runtime.removeDefaultLoggers >>> Runtime.setConfigProvider(configProvider) >>> configurableLogger()
diff --git a/examples/core/src/main/scala/zio/logging/example/LoggerReconfigureApp.scala b/examples/core/src/main/scala/zio/logging/example/LoggerReconfigureApp.scala
index 16476c92..2652ae84 100644
--- a/examples/core/src/main/scala/zio/logging/example/LoggerReconfigureApp.scala
+++ b/examples/core/src/main/scala/zio/logging/example/LoggerReconfigureApp.scala
@@ -40,8 +40,7 @@ object LoggerReconfigureApp extends ZIOAppDefault {
for {
config <- ZIO.succeed(ConfigFactory.load("logger.conf"))
_ <- Console.printLine(config.getConfig("logger")).orDie
- loggerConfig <-
- TypesafeConfigProvider.fromTypesafeConfig(config).nested("logger").load(ConsoleLoggerConfig.config)
+ loggerConfig <- ConsoleLoggerConfig.load().withConfigProvider(TypesafeConfigProvider.fromTypesafeConfig(config))
} yield loggerConfig
)
diff --git a/project/Versions.scala b/project/Versions.scala
index 5e468962..66c738c0 100644
--- a/project/Versions.scala
+++ b/project/Versions.scala
@@ -9,7 +9,7 @@ object Versions {
val zioMetricsConnectorsVersion = "2.3.0"
val zioConfig = "4.0.0-RC16"
val zioParser = "0.1.9"
- val zioPrelude = "1.0.0-RC19"
+ val zioPrelude = "1.0.0-RC21"
val zioHttp = "3.0.0-RC4"
val log4jVersion = "2.19.0"
}