File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
sdk-platform-java/gax-java
gax-grpc/src/test/java/com/google/api/gax/grpc
gax/src/main/java/com/google/api/gax/logging Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,16 @@ class GrpcLoggingInterceptorTest {
6060 @ Mock private ClientCall <String , Integer > call ;
6161
6262 private static final MethodDescriptor <String , Integer > method = FakeMethodDescriptor .create ();
63+ private boolean originalLoggingEnabled ;
64+
65+ @ org .junit .jupiter .api .BeforeEach
66+ void setUpLoggingState () throws Exception {
67+ originalLoggingEnabled = isLoggingEnabled ();
68+ }
6369
6470 @ AfterEach
6571 void tearDown () throws Exception {
66- setLoggingEnabled (false );
72+ setLoggingEnabled (originalLoggingEnabled );
6773 }
6874
6975 @ Test
@@ -141,4 +147,11 @@ private static void setLoggingEnabled(boolean enabled) throws Exception {
141147 method .setAccessible (true );
142148 method .invoke (null , enabled );
143149 }
150+
151+ private static boolean isLoggingEnabled () throws Exception {
152+ Class <?> loggingUtils = Class .forName ("com.google.api.gax.logging.LoggingUtils" );
153+ Method method = loggingUtils .getDeclaredMethod ("isLoggingEnabled" );
154+ method .setAccessible (true );
155+ return (boolean ) method .invoke (null );
156+ }
144157}
Original file line number Diff line number Diff line change 4747class Slf4jUtils {
4848
4949 private static final Logger NO_OP_LOGGER = org .slf4j .helpers .NOPLogger .NOP_LOGGER ;
50- private static final boolean loggingEnabled = LoggingUtils .isLoggingEnabled ();
51-
5250 private static final boolean isSLF4J2x ;
5351
5452 static {
@@ -70,7 +68,7 @@ static Logger getLogger(Class<?> clazz) {
7068
7169 // constructor with LoggerFactoryProvider to make testing easier
7270 static Logger getLogger (Class <?> clazz , LoggerFactoryProvider factoryProvider ) {
73- if (loggingEnabled ) {
71+ if (LoggingUtils . isLoggingEnabled () ) {
7472 ILoggerFactory loggerFactory = factoryProvider .getLoggerFactory ();
7573 return loggerFactory .getLogger (clazz .getName ());
7674 } else {
You can’t perform that action at this time.
0 commit comments