0

How can I seperate logback.xml and logback-test.xml when building rest-api with Ktor? With SpringBoot you can seperate easily and set profile. But how to do it in Ktor?

Thanks for help.

  • Unfortunately, there is no such functionality in Ktor. I suggest using one of the options from this answer https://stackoverflow.com/a/6702128/13963150. – Aleksei Tirman May 31 '22 at 09:31
  • it should be automatically https://logback.qos.ch/faq.html#configFileLocation it not depends on the web framework, it's related to the logger library – Lucas Milotich Sep 18 '22 at 18:48

1 Answers1

0

Maybe it's too late but I had the same problem. I solved that by defining different resources for each environment. You can also have different code per environment. Here is a part of my build.gradle.ktx

val environment: String by project

sourceSets {
    val main by getting {
        when (environment) {
            "dev" -> {
                java.srcDirs("src/main/kotlin", "src/main/dev")
                resources.srcDirs("src/main/dev/resources")
            }

            "prod" -> {
                java.srcDirs("src/main/kotlin", "src/main/prod")
                resources.srcDirs("src/main/prod/resources")
            }

            else -> {
                throw Exception("Please provide 'Environment' variable prod or dev")
            }
        }
    }
}

the default environment can be set in gradle.properties file

environment=dev

also the environment parameter can be passed to gradle run eg:

run -Penvironment=dev