Skip to content

Commit

Permalink
Fix #869 workaround circe-config Boolean codec issue in logstage config
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-kai committed Jan 29, 2020
1 parent d3ac268 commit 3b9fe4a
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package izumi.distage.roles.logger

import com.typesafe.config.Config
import io.circe.Decoder
import io.circe.{Decoder, Json}
import izumi.distage.config.codec.{CirceDerivationConfigStyle, ConfigReader}
import izumi.distage.roles.logger.SimpleLoggerConfigurator.SinksConfig
import izumi.logstage.api.config.{LoggerConfig, LoggerPathConfig}
Expand Down Expand Up @@ -70,7 +70,23 @@ object SimpleLoggerConfigurator {
layout: Option[String],
)
object SinksConfig {
implicit val decoder: Decoder[SinksConfig] = CirceDerivationConfigStyle.deriveDecoder
implicit val decoder: Decoder[SinksConfig] = for {
levels <- Decoder.forProduct1("levels")(identity[Map[String, List[String]]])
options <- Decoder.forProduct1("options")(identity[Option[RenderingOptions]])
json <- Decoder.forProduct1("json")((_: Json).fold(
jsonNull = None,
jsonBoolean = Some(_),
jsonNumber = _ => None,
jsonString = { str =>
if (Set("true", "on").contains(str)) Some(true)
else if (Set("false", "off").contains(str)) Some(false)
else None
},
jsonArray = _ => None,
jsonObject = _ => None,
))
layout <- Decoder.forProduct1("layout")(identity[Option[String]])
} yield SinksConfig(levels, options, json, layout)
implicit val configReader: ConfigReader[SinksConfig] = ConfigReader.deriveFromCirce
}
}

0 comments on commit 3b9fe4a

Please sign in to comment.