Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SLF4J conflict with Kotlin scripting, default log level #203

Merged
merged 8 commits into from
Apr 7, 2024

Conversation

gabrielfeo
Copy link
Owner

@gabrielfeo gabrielfeo commented Apr 6, 2024

In #178, logging was changed to SLF4J and logback-classic. To keep it possible to set the log level via environment variables (Config.logLevel / DEVELOCITY_API_LOG_LEVEL), a small hack was in place. Kotlin scripts, which have slf4j-simple in the classpath by default, crashed due to this hack.

java.lang.ClassCastException: class org.slf4j.impl.SimpleLogger cannot be cast to class ch.qos.logback.classic.Logger (org.slf4j.impl.SimpleLogger is in unnamed module of loader java.net.URLClassLoader @3a0f0552; ch.qos.logback.classic.Logger is in unnamed module of loader java.net.URLClassLoader @47b530e0)
        at com.gabrielfeo.develocity.api.internal.RealLoggerFactory.newLogger(LoggerFactory.kt:17)
        at com.gabrielfeo.develocity.api.internal.OkHttpClientKt.addNetworkInterceptors(OkHttpClient.kt:61)
        at com.gabrielfeo.develocity.api.internal.OkHttpClientKt.buildOkHttpClient(OkHttpClient.kt:35)
        at com.gabrielfeo.develocity.api.RealDevelocityApi$okHttpClient$2.invoke(DevelocityApi.kt:72)
        at com.gabrielfeo.develocity.api.RealDevelocityApi$okHttpClient$2.invoke(DevelocityApi.kt:71)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.gabrielfeo.develocity.api.RealDevelocityApi.getOkHttpClient(DevelocityApi.kt:71)
        at com.gabrielfeo.develocity.api.RealDevelocityApi.access$getOkHttpClient(DevelocityApi.kt:67)
        at com.gabrielfeo.develocity.api.RealDevelocityApi$retrofit$2.invoke(DevelocityApi.kt:78)
        at com.gabrielfeo.develocity.api.RealDevelocityApi$retrofit$2.invoke(DevelocityApi.kt:75)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.gabrielfeo.develocity.api.RealDevelocityApi.getRetrofit(DevelocityApi.kt:75)
        at com.gabrielfeo.develocity.api.RealDevelocityApi.access$getRetrofit(DevelocityApi.kt:67)
        at com.gabrielfeo.develocity.api.RealDevelocityApi$buildsApi$2.invoke(DevelocityApi.kt:84)
        at com.gabrielfeo.develocity.api.RealDevelocityApi$buildsApi$2.invoke(DevelocityApi.kt:84)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.gabrielfeo.develocity.api.RealDevelocityApi.getBuildsApi(DevelocityApi.kt:84)
        at Example_script_main$builds$1.invokeSuspend(example-script.main.kts:39)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:48)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at Example_script_main.<init>(example-script.main.kts:38)

Also, the default log level was 'info', but it was supposed to be 'off'.

  • Remove logback and any reference to SLF4J impls
  • Add slf4j-simple instead with a simpler hack ✨ to set the log level from environment variables
  • Fix the default log level to be 'off', unless it'd conflict with the user's own SimpleLogger default
  • Document what the llbrary logs on each log level

Copy link
Contributor

github-actions bot commented Apr 6, 2024

Generated API diff

@gabrielfeo gabrielfeo enabled auto-merge (squash) April 7, 2024 00:14
@gabrielfeo gabrielfeo merged commit fc05dd6 into main Apr 7, 2024
8 checks passed
@gabrielfeo gabrielfeo deleted the gaf/fix-logging branch April 7, 2024 00:17
@gabrielfeo gabrielfeo restored the gaf/fix-logging branch November 30, 2024 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant