Skip to content

Commit

Permalink
Merge pull request #27754 from guardian/aa/config-log
Browse files Browse the repository at this point in the history
Log how a config value has been resolved
  • Loading branch information
akash1810 authored Jan 29, 2025
2 parents 21ba826 + 6635b15 commit 1ac9f20
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions common/app/common/configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BadConfigurationException(msg: String) extends RuntimeException(msg)

object Environment extends GuLogging {

private[this] val installVars = {
private[this] val installVars: Map[String, String] = {
val source = new File("/etc/gu/install_vars") match {
case f if f.exists => IOUtils.toString(new FileInputStream(f), Charset.defaultCharset())
case _ => ""
Expand All @@ -34,7 +34,17 @@ object Environment extends GuLogging {

// Prefer env vars over install vars over default
private[this] def get(name: String, default: String): String = {
sys.env.get(name.toUpperCase).orElse(installVars.get(name)).getOrElse(default)
sys.env.get(name.toUpperCase) match {
case Some(env) =>
log.info(s"Environment lookup: resolved $name from environment variable")
env
case _ if installVars.contains(name) =>
log.info(s"Environment lookup: resolved $name from install_vars")
installVars(name)
case _ =>
log.info(s"Environment lookup: resolved $name from default value")
default
}
}

val stack = get("stack", "frontend")
Expand Down

0 comments on commit 1ac9f20

Please sign in to comment.