-
Notifications
You must be signed in to change notification settings - Fork 40.4k
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
jdk http client wire logging improvements #40872
Comments
Sorry @xenoterracide, I'm having a hard time following the description. Can you clarify the problem your having? |
@philwebb basically figuring out how to do wire logging with the jdk implementation is a pain, and requires several non obvious and not so google-able steps. I think there may be a code improvement or two that spring boot could take. Add jpl to the log4j2 starter (is this also needed for slf4j?) |
Ahh OK. I think I get it. The
Quite possibly. We have
I guess this is needed because of some limitation with the |
Looks like https://github.com/qos-ch/slf4j/tree/master/slf4j-jdk-platform-logging might be what we want. |
maybe, although if you're using log4j the artifact is log4j-jpl it's already available in the dependency list, just not added in the log4j starter. Unless the plan would be to jlp -> jul -> slf4j -> log4j in my case... (note: I was told that jlp might already proxy through jul, but I'm not certain of that...).
yes, but... as far as I know you can't set that in
yes, or at least |
As described in the JEP for the Platform Logging API, platform logging is routed into JUL by default. We already have things set up to route JUL into Logback of Log4j2 so it should work out of the box with Boot's default logging configuration. Some experimentation shows this to be the case with both Logback and Log4j2. With When Similar to As far as I can tell, the only thing that has to be done here is to turn on the HTTP client's logging and things will then work as expected. I'm not sure that we should document how to turn on the HTTP client's logging as it's a JDK feature that's already described in the javadoc since Java 20 and in the developer guide since at least Java 17. Furthermore, Boot itself only has minimal support for Framework's Beyond this, would could consider adding |
I've been getting this consistently... and I just figured out why. I was seeing info logs, so I thought they were enabled, turns out it's the "we can't disable these before application.properties" is parsed issue. Another profile was disabling them.
so... I thought I tested removing this... I'm not certain how, but it is working without this change. this is on my list of gradle cache somewhere, potential for Idea screwing it up high if I only tested through Idea's gradle runner.
is it impossible to make a change to set this this via package org.example.jdkhttpclient;
import static org.assertj.core.api.Assertions.assertThat;
import java.net.http.HttpClient;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import org.springframework.web.client.RestClient;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class JdkHttpClientApplicationTests {
static {
System.setProperty("jdk.httpclient.HttpClient.log", "all");
}
@Autowired
ObjectFactory<RestClient> oauthTestClient;
@Test
void contextLoads() {
var greeting = oauthTestClient.getObject().get().uri("/").retrieve().toEntity(JdkHttpClientApplication.Greeting.class);
assertThat(greeting.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@TestConfiguration
static class TestConfig {
@Bean
@Lazy
RestClient oauthTestClient(@LocalServerPort int port) {
return RestClient.builder()
.requestFactory(
new JdkClientHttpRequestFactory(HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NEVER).build())
)
.baseUrl("http://localhost:" + port)
.build();
}
}
} |
It's not impossible, but I'm also not sure it's something that we should do. I don't think we'd want to hardcode knowledge of One problem with this approach is that not all system properties will work unless they're present when the JVM's launched. Gradle avoids this to some extent when it forks its daemon and can control its command line but we do not have that option. There's also Boot's relaxed binding and support for things like environment variables to consider. We wouldn't be able to turn something like Let's see what the outcome of the team's discussion is. |
We discussed this today and we don't think setting the system property from |
So this has been a pain to figure out. I need to go add an SO answer I think. looks like the minimum is:
in gradle or maven, doesn't look like
application.properties
will pick it up. Could this be changedif using log4j add (maybe this could be added to the starter)
log4j-jpl
set this regardless of what the root logger is set to. Note: not having it is a sensible default, but it's not intuitive that if the root logger is set to info that this isn't.
would be good, imho, to improve documentation around this at the minimum, but perhaps other changes could happen too.
The text was updated successfully, but these errors were encountered: