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

Add logging of requests and responses #151

Closed
vbauer opened this issue Jan 24, 2015 · 11 comments
Closed

Add logging of requests and responses #151

vbauer opened this issue Jan 24, 2015 · 11 comments

Comments

@vbauer
Copy link

vbauer commented Jan 24, 2015

Add possibility to log requests and responses.
It will help to understand a lot of cases when library does not work.

@KostyaSha
Copy link
Contributor

Could you describe what problems do you have? There are some issues when logging wouldn't help you at all.

@vbauer
Copy link
Author

vbauer commented Mar 17, 2015

I faced with the following problem:

github-api works fine if I send requests by portions (~200-1000 for one time), but it works very unstable when I make a lot of requests (~4000) for a short period of time (it hangs or throws strange NPE).

It is not critical issue for me, as I said, I just send request by portions, but it will be interesting to know the root of this problem. It looks like (sometimes) Github responds incorrectly and github-api does not process it correctly (or some problems with concurrency).

@KostyaSha
Copy link
Contributor

This maybe related to #159 and #160. For NPE we will need stacktrace or any debug information. I can suggest run your tool under debugger and add Exception breakpoint.

@vbauer
Copy link
Author

vbauer commented Mar 17, 2015

Ok, I'll try to reproduce this problems tomorrow.

@szpak
Copy link
Contributor

szpak commented Apr 4, 2016

When embedding in own tools (like maven/gradle plugin) it could be useful to help diagnose end user problems.

@rmetzger
Copy link
Contributor

rmetzger commented Feb 7, 2019

You should be able to use OkHttp with Logging interceptors:

Cache cache = new Cache(new File(cacheDir), cacheMB * 1024 * 1024);
        try {
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
                @Override
                public void log(String message) {
                    System.out.println("Intercepted " + message);
                }
            });
            logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);

            OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
            okHttpClient.addInterceptor(logging);
            okHttpClient.cache(cache);

            gitHub = GitHubBuilder.fromEnvironment().withPassword("", "")
                    .withConnector(new OkHttp3Connector(new OkUrlFactory(okHttpClient.build())))
                    .build();

This should, but does not work for me :)

@bitwiseman
Copy link
Member

@rmetzger
Logging interceptors: I think this is due to the way we use OkHttp. Working toward upgrading.

@marcin-majewski-sonarsource

@rmetzger Did you at the end manage to get it right? I have the same working example, and the logging interceptors are not called.

@rmetzger
Copy link
Contributor

IIRC I didn't manage to fix this :( @bitwiseman's comment seem to confirm that this is currently not supported.

@bitwiseman
Copy link
Member

@marcin-majewski-sonarsource
There is basic logging in this library now:

private void logRequest(@Nonnull final GitHubRequest request) {
LOGGER.log(FINE,
() -> "GitHub API request [" + (login == null ? "anonymous" : login) + "]: " + request.method() + " "
+ request.url().toString());

But full logging requires moving to a non-HttpUrlConnection system (#1085). We could update ObsoleteUrlFactory but that would require significant testing.

@bitwiseman
Copy link
Member

Closed by #1290.
Switch to OkHttpGitHubConnector to avoid ObsoleteUrlFactory and have full interceptor behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants