-
Notifications
You must be signed in to change notification settings - Fork 74
MLE-29643 Configure OkHttp Logging with dedicated logger #1957
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
+180
−28
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
marklogic-client-api/src/main/java/com/marklogic/client/util/LoggingUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||
| */ | ||
| package com.marklogic.client.util; | ||
|
|
||
| /** | ||
| * Provides public constants for configuring MarkLogic Java Client logging behaviour. | ||
| * | ||
| * <h2>OkHttp Network Logging</h2> | ||
| * | ||
| * <p>The Java Client uses OkHttp for all HTTP communication with MarkLogic. Optional network | ||
| * traffic logging is controlled by two Java system properties: | ||
| * | ||
| * <ul> | ||
| * <li>{@link #OKHTTP_NETWORK_LEVEL} — controls the verbosity of logged HTTP traffic.</li> | ||
| * <li>{@link #OKHTTP_NETWORK_OUTPUT} — controls where log lines are written.</li> | ||
| * </ul> | ||
| * | ||
| * <p>When the output is set to {@code LOGGER}, log lines are written to the SLF4J logger | ||
| * category {@link #OKHTTP_NETWORK_LOGGER} at {@code INFO} level. Configure this category | ||
| * in your logging framework to enable network diagnostics without enabling debug logging | ||
| * for unrelated client internals. For example, in {@code logback.xml}: | ||
| * | ||
| * <pre>{@code | ||
| * <logger name="marklogic.okhttp.network" level="INFO"/> | ||
| * }</pre> | ||
| * | ||
| * <p>Or in a Spring Boot {@code application.properties} file: | ||
| * | ||
| * <pre>{@code | ||
| * logging.level.marklogic.okhttp.network=INFO | ||
| * }</pre> | ||
| * | ||
| * <p><strong>Security warning:</strong> {@code Authorization} and {@code x-auth-token} header | ||
| * values are automatically redacted from all log output. However, {@code HEADERS} and | ||
| * {@code BODY} levels may expose other sensitive data including MarkLogic document content. | ||
| * Never enable {@code HEADERS} or {@code BODY} in a production environment. | ||
| * | ||
| * @since 8.2.0 | ||
| */ | ||
| public final class LoggingUtil { | ||
|
|
||
| /** | ||
| * Name of the Java system property that controls the verbosity of OkHttp network logging. | ||
| * Value: {@code "marklogic.okhttp.network.level"} | ||
| * | ||
| * <p>Accepted values (case-insensitive): {@code BASIC}, {@code HEADERS}, {@code BODY}, | ||
| * {@code NONE}. Setting this property to any recognised value activates the network | ||
| * logging interceptor. | ||
| * | ||
| * <p><strong>Security warning:</strong> {@code HEADERS} and {@code BODY} levels log HTTP | ||
| * request and response headers and/or bodies, which may contain MarkLogic credentials, | ||
| * OAuth/SAML tokens, or sensitive document content. These levels must <em>never</em> be | ||
| * enabled in production environments. {@code Authorization} and {@code x-auth-token} | ||
| * header values are automatically redacted, but body content is not. | ||
| */ | ||
| public static final String OKHTTP_NETWORK_LEVEL = "marklogic.okhttp.network.level"; | ||
|
|
||
| /** | ||
| * Name of the Java system property that controls where OkHttp network log lines are written. | ||
| * Value: {@code "marklogic.okhttp.network.output"} | ||
| * | ||
| * <p>Accepted values (case-insensitive): | ||
| * <ul> | ||
| * <li>{@code LOGGER} — writes to the SLF4J logger category {@link #OKHTTP_NETWORK_LOGGER} | ||
| * at {@code INFO} level.</li> | ||
| * <li>{@code STDERR} — writes to {@code System.err}.</li> | ||
| * <li>unset — writes to {@code System.out}.</li> | ||
| * </ul> | ||
| */ | ||
| public static final String OKHTTP_NETWORK_OUTPUT = "marklogic.okhttp.network.output"; | ||
|
|
||
| /** | ||
| * The SLF4J logger category used for OkHttp network traffic when | ||
| * {@link #OKHTTP_NETWORK_OUTPUT} is set to {@code LOGGER}. | ||
| * Value: {@code "marklogic.okhttp.network"} | ||
| * | ||
| * <p>Configure this category at {@code INFO} level in your logging framework to enable | ||
| * network traffic logging. Example {@code logback.xml} configuration: | ||
| * <pre>{@code | ||
| * <logger name="marklogic.okhttp.network" level="INFO"/> | ||
| * }</pre> | ||
| * | ||
| * <p>Example Spring Boot {@code application.properties}: | ||
| * <pre>{@code | ||
| * logging.level.marklogic.okhttp.network=INFO | ||
| * }</pre> | ||
| */ | ||
| public static final String OKHTTP_NETWORK_LOGGER = "marklogic.okhttp.network"; | ||
|
|
||
| private LoggingUtil() { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an FYI - you may like
io.github.hakky54:logcaptorfor tests that capture and assert on log messages. You can see it in action in marklogic-spark-connector - e.g.But using the Logback APIs directly is fine too.