Changeset 15389 in josm


Ignore:
Timestamp:
2019-09-29T22:47:44+02:00 (5 years ago)
Author:
Don-vip
Message:

allow to set HttpClient log level to DEBUG

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r15233 r15389  
    6969    private Response response;
    7070    private boolean finishOnCloseOutput = true;
     71    private boolean debug;
    7172
    7273    // Pattern to detect Tomcat error message. Be careful with change of format:
     
    142143                cr = performConnection();
    143144                final boolean hasReason = reasonForRequest != null && !reasonForRequest.isEmpty();
    144                 Logging.info("{0} {1}{2} -> {3} {4}{5}",
     145                logRequest("{0} {1}{2} -> {3} {4}{5}",
    145146                        getRequestMethod(), getURL(), hasReason ? (" (" + reasonForRequest + ')') : "",
    146147                        cr.getResponseVersion(), cr.getResponseCode(),
     
    160161                }
    161162            } catch (IOException | RuntimeException e) {
    162                 Logging.info("{0} {1} -> !!!", requestMethod, url);
     163                logRequest("{0} {1} -> !!!", requestMethod, url);
    163164                Logging.warn(e);
    164165                //noinspection ThrowableResultOfMethodCallIgnored
     
    175176                    url = new URL(url, redirectLocation);
    176177                    maxRedirects--;
    177                     Logging.info(tr("Download redirected to ''{0}''", redirectLocation));
     178                    logRequest(tr("Download redirected to ''{0}''", redirectLocation));
    178179                    response = connect();
    179180                    successfulConnection = true;
     
    207208    }
    208209
     210    protected final void logRequest(String pattern, Object... args) {
     211        if (debug) {
     212            Logging.debug(pattern, args);
     213        } else {
     214            Logging.info(pattern, args);
     215        }
     216    }
     217
    209218    protected final void logRequestBody() {
    210         Logging.info("{0} {1} ({2}) ...", requestMethod, url, Utils.getSizeString(requestBody.length, Locale.getDefault()));
     219        logRequest("{0} {1} ({2}) ...", requestMethod, url, Utils.getSizeString(requestBody.length, Locale.getDefault()));
    211220        if (Logging.isTraceEnabled() && hasRequestBody()) {
    212221            Logging.trace("BODY: {0}", new String(requestBody, StandardCharsets.UTF_8));
     
    801810    }
    802811
     812    /**
     813     * Sets the connect log at DEBUG level instead of the default INFO level.
     814     * @param debug {@code true} to set the connect log at DEBUG level
     815     * @return {@code this}
     816     * @since 15389
     817     */
     818    public final HttpClient setLogAtDebug(boolean debug) {
     819        this.debug = debug;
     820        return this;
     821    }
     822
    803823    private static boolean isRedirect(final int statusCode) {
    804824        switch (statusCode) {
Note: See TracChangeset for help on using the changeset viewer.