Skip to content

Commit 8294d78

Browse files
committed
fix(gax): make isLoggingEnabled and setLoggingEnabled package private
1 parent 741cb2c commit 8294d78

3 files changed

Lines changed: 10 additions & 30 deletions

File tree

gax-java/gax/src/main/java/com/google/api/gax/logging/LoggingUtils.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,47 +37,28 @@
3737
public class LoggingUtils {
3838

3939
static final String GOOGLE_SDK_JAVA_LOGGING = "GOOGLE_SDK_JAVA_LOGGING";
40-
static final String GOOGLE_SDK_JAVA_LOGGING_V2 = "GOOGLE_SDK_JAVA_LOGGING_V2";
4140

4241
private static boolean loggingEnabled = checkLoggingEnabled(GOOGLE_SDK_JAVA_LOGGING);
43-
private static boolean loggingV2Enabled = checkLoggingEnabled(GOOGLE_SDK_JAVA_LOGGING_V2);
4442

4543
/**
46-
* Returns whether client-side logging is enabled (V1 or V2).
44+
* Returns whether client-side logging is enabled.
4745
*
4846
* @return true if logging is enabled, false otherwise.
4947
*/
50-
public static boolean isLoggingEnabled() {
51-
return loggingEnabled || loggingV2Enabled;
52-
}
53-
54-
/**
55-
* Returns whether client-side logging V2 (Actionable Errors) is enabled.
56-
*
57-
* @return true if V2 logging is enabled, false otherwise.
58-
*/
59-
public static boolean isLoggingV2Enabled() {
60-
return loggingV2Enabled;
48+
static boolean isLoggingEnabled() {
49+
return loggingEnabled;
6150
}
6251

6352
/**
6453
* Sets whether client-side logging is enabled. Visible for testing.
6554
*
6655
* @param enabled true to enable logging, false to disable.
6756
*/
68-
public static void setLoggingEnabled(boolean enabled) {
57+
@com.google.common.annotations.VisibleForTesting
58+
static void setLoggingEnabled(boolean enabled) {
6959
loggingEnabled = enabled;
7060
}
7161

72-
/**
73-
* Sets whether client-side logging V2 is enabled. Visible for testing.
74-
*
75-
* @param enabled true to enable logging, false to disable.
76-
*/
77-
public static void setLoggingV2Enabled(boolean enabled) {
78-
loggingV2Enabled = enabled;
79-
}
80-
8162
private static boolean checkLoggingEnabled(String envVar) {
8263
String enableLogging = System.getenv(envVar);
8364
return "true".equalsIgnoreCase(enableLogging);

gax-java/gax/src/main/java/com/google/api/gax/logging/Slf4jLoggingHelpers.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ static void logResponse(
114114
LoggingUtils.executeWithTryCatch(
115115
() -> {
116116
Logger logger = loggerProvider.getLogger();
117-
boolean isV2 = LoggingUtils.isLoggingV2Enabled();
118-
if (!isV2 && logger.isInfoEnabled()) {
117+
if (logger.isInfoEnabled()) {
119118
logDataBuilder.responseStatus(status);
120119
}
121-
if (!isV2 && logger.isInfoEnabled() && !logger.isDebugEnabled()) {
120+
if (logger.isInfoEnabled() && !logger.isDebugEnabled()) {
122121
Map<String, Object> responseData = logDataBuilder.build().toMapResponse();
123122
Slf4jUtils.log(logger, Level.INFO, responseData, "Received response");
124123
}

gax-java/gax/src/test/java/com/google/api/gax/logging/LoggingUtilsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ void testLogActionableError_loggingDisabled() {
105105

106106
@Test
107107
void testLogActionableError_success() {
108-
LoggingUtils.setLoggingV2Enabled(true);
108+
LoggingUtils.setLoggingEnabled(true);
109109
LoggerProvider loggerProvider = mock(LoggerProvider.class);
110110
Logger logger = mock(Logger.class);
111111
when(loggerProvider.getLogger()).thenReturn(logger);
112112

113113
org.slf4j.spi.LoggingEventBuilder eventBuilder = mock(org.slf4j.spi.LoggingEventBuilder.class);
114-
when(logger.atInfo()).thenReturn(eventBuilder);
114+
when(logger.atDebug()).thenReturn(eventBuilder);
115115
when(eventBuilder.addKeyValue(anyString(), any())).thenReturn(eventBuilder);
116116

117117
Map<String, Object> context = Collections.singletonMap("key", "value");
118-
LoggingUtils.logActionableError(context, loggerProvider, org.slf4j.event.Level.INFO, "message");
118+
LoggingUtils.logActionableError(context, loggerProvider, org.slf4j.event.Level.DEBUG, "message");
119119

120120
verify(loggerProvider).getLogger();
121121
}

0 commit comments

Comments
 (0)