feat: Customize logging level through environment variable

This commit is contained in:
oSumAtrIX 2024-09-28 16:10:58 +02:00
parent 1e3e46ff4f
commit 8b17d8894d
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 15 additions and 21 deletions

View File

@ -1,6 +1,7 @@
package app.revanced.api.command package app.revanced.api.command
import app.revanced.api.configuration.* import app.revanced.api.configuration.*
import io.github.cdimascio.dotenv.Dotenv
import io.ktor.server.engine.* import io.ktor.server.engine.*
import io.ktor.server.jetty.* import io.ktor.server.jetty.*
import picocli.CommandLine import picocli.CommandLine
@ -33,6 +34,8 @@ internal object StartAPICommand : Runnable {
private var configFile = File("configuration.toml") private var configFile = File("configuration.toml")
override fun run() { override fun run() {
Dotenv.configure().systemProperties().load()
embeddedServer(Jetty, port, host) { embeddedServer(Jetty, port, host) {
configureDependencies(configFile) configureDependencies(configFile)
configureHTTP() configureHTTP()

View File

@ -12,7 +12,6 @@ import app.revanced.api.configuration.services.OldApiService
import app.revanced.api.configuration.services.PatchesService import app.revanced.api.configuration.services.PatchesService
import com.akuleshov7.ktoml.Toml import com.akuleshov7.ktoml.Toml
import com.akuleshov7.ktoml.source.decodeFromStream import com.akuleshov7.ktoml.source.decodeFromStream
import io.github.cdimascio.dotenv.Dotenv
import io.ktor.client.* import io.ktor.client.*
import io.ktor.client.engine.okhttp.* import io.ktor.client.engine.okhttp.*
import io.ktor.client.plugins.* import io.ktor.client.plugins.*
@ -38,11 +37,7 @@ import java.io.File
fun Application.configureDependencies( fun Application.configureDependencies(
configFile: File, configFile: File,
) { ) {
val globalModule = module { val miscModule = module {
single {
Dotenv.configure().load()
}
factory { params -> factory { params ->
val defaultRequestUri: String = params.get<String>() val defaultRequestUri: String = params.get<String>()
val configBlock = params.getOrNull<(HttpClientConfig<OkHttpConfig>.() -> Unit)>() ?: {} val configBlock = params.getOrNull<(HttpClientConfig<OkHttpConfig>.() -> Unit)>() ?: {}
@ -72,7 +67,7 @@ fun Application.configureDependencies(
) )
} }
get<Dotenv>()["BACKEND_API_TOKEN"]?.let { System.getProperty("BACKEND_API_TOKEN")?.let {
install(Auth) { install(Auth) {
bearer { bearer {
loadTokens { loadTokens {
@ -98,12 +93,10 @@ fun Application.configureDependencies(
} }
single { single {
val dotenv = get<Dotenv>()
TransactionManager.defaultDatabase = Database.connect( TransactionManager.defaultDatabase = Database.connect(
url = dotenv["DB_URL"], url = System.getProperty("DB_URL"),
user = dotenv["DB_USER"], user = System.getProperty("DB_USER"),
password = dotenv["DB_PASSWORD"], password = System.getProperty("DB_PASSWORD"),
) )
AnnouncementRepository() AnnouncementRepository()
@ -112,13 +105,11 @@ fun Application.configureDependencies(
val serviceModule = module { val serviceModule = module {
single { single {
val dotenv = get<Dotenv>() val jwtSecret = System.getProperty("JWT_SECRET")
val issuer = System.getProperty("JWT_ISSUER")
val validityInMin = System.getProperty("JWT_VALIDITY_IN_MIN").toLong()
val jwtSecret = dotenv["JWT_SECRET"] val authSHA256DigestString = System.getProperty("AUTH_SHA256_DIGEST")
val issuer = dotenv["JWT_ISSUER"]
val validityInMin = dotenv["JWT_VALIDITY_IN_MIN"].toLong()
val authSHA256DigestString = dotenv["AUTH_SHA256_DIGEST"]
AuthenticationService(issuer, validityInMin, jwtSecret, authSHA256DigestString) AuthenticationService(issuer, validityInMin, jwtSecret, authSHA256DigestString)
} }
@ -140,7 +131,7 @@ fun Application.configureDependencies(
install(Koin) { install(Koin) {
modules( modules(
globalModule, miscModule,
repositoryModule, repositoryModule,
serviceModule, serviceModule,
) )

View File

@ -16,7 +16,7 @@ fun Application.configureHTTP() {
configurationRepository.corsAllowedHosts.forEach { host -> configurationRepository.corsAllowedHosts.forEach { host ->
allowHost( allowHost(
host = host, host = host,
schemes = listOf("http", "https") schemes = listOf("http", "https"),
) )
} }
} }

View File

@ -4,7 +4,7 @@
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> <pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder> </encoder>
</appender> </appender>
<root level="info"> <root level="\${LOG_LEVEL:-INFO}">
<appender-ref ref="STDOUT"/> <appender-ref ref="STDOUT"/>
</root> </root>
</configuration> </configuration>