-
Notifications
You must be signed in to change notification settings - Fork 231
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
feat: add client logging with slf4j #1586
Open
zhumin8
wants to merge
25
commits into
main
Choose a base branch
from
client-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c38282b
add slf4j and other test dep. add logging utils. add logging to req/r…
zhumin8 3f30267
remove JUL wrapper as fallback condition. Other test setups.
zhumin8 35d9a75
remove unused LoggingInterceptor.
zhumin8 a63d6fe
revert unintential change to test. add comments.
zhumin8 83329e7
remove public from LoggingUtils.
zhumin8 6a5d3d3
downgrade logback and remove unused.
zhumin8 930d0aa
put logging inside try-catch block to avoid crashing for logging errors.
zhumin8 44f3de8
simplify logic for getLogger. remove unused argLine for maven-surefir…
zhumin8 598d5b9
logging util class refactor.
zhumin8 445fe08
fix test setup timing issue.
zhumin8 a7f5a5e
add tests. feedback. minor cleanups.
zhumin8 8bc1ae7
TestAppender change to per test. add LoggingTest.
zhumin8 bde6ede
update messages.
zhumin8 7c89c3f
test setup - try use env for all test in ci.
zhumin8 6da450d
add env set to sonar test.
zhumin8 9e20be9
duplicate fields to log in message. add tests.
zhumin8 db99e70
add tests.
zhumin8 68307fc
minor cleanup and comment.
zhumin8 4202902
fix add env to sonar ci.
zhumin8 cfbe873
add log env to integration in build.sh
zhumin8 858b725
deps: add gson explicitly. move gson and slf4j-api version to parent …
zhumin8 fb8889a
deps: explicitly declare org.hamcrest:hamcrest-core:test
zhumin8 15d3016
update logging messages to rm 'auth'.
zhumin8 c2a8d76
make sensitive key comparison case insensitive.
zhumin8 6485526
extract env var name.
zhumin8 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 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 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 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 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 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 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
80 changes: 80 additions & 0 deletions
80
oauth2_http/java/com/google/auth/oauth2/LoggingConfigs.java
This file contains 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,80 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following disclaimer | ||
* in the documentation and/or other materials provided with the | ||
* distribution. | ||
* | ||
* * Neither the name of Google LLC nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.google.auth.oauth2; | ||
|
||
import org.slf4j.ILoggerFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
class LoggingConfigs { | ||
|
||
private static EnvironmentProvider environmentProvider = SystemEnvironmentProvider.getInstance(); | ||
private static final Logger NO_OP_LOGGER = org.slf4j.helpers.NOPLogger.NOP_LOGGER; | ||
private static boolean loggingEnabled = isLoggingEnabled(); | ||
// expose this setter only for testing purposes | ||
static void setEnvironmentProvider(EnvironmentProvider provider) { | ||
environmentProvider = provider; | ||
// Recalculate LOGGING_ENABLED after setting the new provider | ||
loggingEnabled = isLoggingEnabled(); | ||
} | ||
lqiu96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private LoggingConfigs() {} | ||
|
||
static Logger getLogger(Class<?> clazz) { | ||
return getLogger(clazz, new DefaultLoggerFactoryProvider()); | ||
} | ||
|
||
// constructor with LoggerFactoryProvider to make testing easier | ||
static Logger getLogger(Class<?> clazz, LoggerFactoryProvider factoryProvider) { | ||
if (!loggingEnabled) { | ||
// use SLF4j's NOP logger regardless of bindings | ||
return NO_OP_LOGGER; | ||
} | ||
return factoryProvider.getLoggerFactory().getLogger(clazz.getName()); | ||
} | ||
|
||
static boolean isLoggingEnabled() { | ||
String enableLogging = environmentProvider.getEnv("GOOGLE_SDK_JAVA_LOGGING"); | ||
lqiu96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "true".equalsIgnoreCase(enableLogging); | ||
} | ||
|
||
interface LoggerFactoryProvider { | ||
ILoggerFactory getLoggerFactory(); | ||
} | ||
|
||
static class DefaultLoggerFactoryProvider implements LoggerFactoryProvider { | ||
@Override | ||
public ILoggerFactory getLoggerFactory() { | ||
return LoggerFactory.getILoggerFactory(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
for next release: this env var is probably only needed for LoggingTest.java class.