Skip to content

Commit

Permalink
examples and docs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoon committed Dec 26, 2023
1 parent 5fbcefd commit 3c3b5b9
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 60 deletions.
183 changes: 152 additions & 31 deletions docs/reconfigurable-logger.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/slf4j1-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ val logger = Runtime.removeDefaultLoggers >>> consoleJsonLogger() >+> Slf4jBridg
```
<br/>

**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.


Expand Down
2 changes: 1 addition & 1 deletion docs/slf4j2-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ val logger = Runtime.removeDefaultLoggers >>> consoleJsonLogger() >+> Slf4jBridg

<br/>

**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.


Expand Down
1 change: 1 addition & 0 deletions examples/core/src/main/resources/logger.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ logger {
filter {
rootLevel = "INFO"
mappings {
"zio.logging.example" = "DEBUG"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,27 +36,17 @@ 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)
}
}
.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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 3c3b5b9

Please sign in to comment.