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

Move from java.util logging to SLF4J #178

Merged
merged 5 commits into from
Apr 2, 2024
Merged

Conversation

gabrielfeo
Copy link
Owner

No description provided.

@gabrielfeo gabrielfeo changed the title Move from java.util logging to SLF4j Move from java.util logging to SLF4J Apr 2, 2024
@gabrielfeo gabrielfeo enabled auto-merge (squash) April 2, 2024 23:13
Copy link
Contributor

github-actions bot commented Apr 2, 2024

Generated API diff

@gabrielfeo gabrielfeo merged commit 72f75f3 into next Apr 2, 2024
8 checks passed
@gabrielfeo gabrielfeo deleted the gaf/logging-overhaul branch April 2, 2024 23:25
gabrielfeo added a commit that referenced this pull request Apr 7, 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][1], 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

[1]:
https://github.com/JetBrains/kotlin/blob/27c6d00cb2a5f9c0e9df62b021600e1263f5201a/libraries/tools/kotlin-main-kts/build.gradle.kts#L44
@gabrielfeo gabrielfeo restored the gaf/logging-overhaul 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