Merge branch 'stable-3.1' into stable-3.2
* stable-3.1:
LoggingContext: Avoid unboxing of Boolean to primitive boolean
Initialize Flogger backend in TestLoggingActivator#configureLogging
TestLoggingActivator: Add a private default constructor
FloggerInitializer: Add a private default constructor
Fix minor spelling mistake in trace log messages
Use dedicated database connection for every schema migration
ConfigSuite: Externalize flogger initialization in its own class
Change-Id: I52558d45ae8f46ef87ddece09715c4f75db0ab4a
diff --git a/java/com/google/gerrit/server/logging/LoggingContext.java b/java/com/google/gerrit/server/logging/LoggingContext.java
index bc5634df..36c7e9e 100644
--- a/java/com/google/gerrit/server/logging/LoggingContext.java
+++ b/java/com/google/gerrit/server/logging/LoggingContext.java
@@ -144,8 +144,7 @@
}
boolean isLoggingForced() {
- Boolean force = forceLogging.get();
- return force != null ? force : false;
+ return Boolean.TRUE.equals(forceLogging.get());
}
boolean forceLogging(boolean force) {
@@ -155,7 +154,7 @@
} else {
forceLogging.remove();
}
- return oldValue != null ? oldValue : false;
+ return Boolean.TRUE.equals(oldValue);
}
boolean isPerformanceLogging() {
diff --git a/java/com/google/gerrit/testing/ConfigSuite.java b/java/com/google/gerrit/testing/ConfigSuite.java
index c3a4192..d7ae397 100644
--- a/java/com/google/gerrit/testing/ConfigSuite.java
+++ b/java/com/google/gerrit/testing/ConfigSuite.java
@@ -24,7 +24,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import com.google.gerrit.server.logging.LoggingContext;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@@ -107,16 +106,6 @@
* field annotated with {@code @ConfigSuite.Name}.
*/
public class ConfigSuite extends Suite {
- private static final String FLOGGER_BACKEND_PROPERTY = "flogger.backend_factory";
- private static final String FLOGGER_LOGGING_CONTEXT = "flogger.logging_context";
-
- static {
- System.setProperty(
- FLOGGER_BACKEND_PROPERTY,
- "com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance");
- System.setProperty(FLOGGER_LOGGING_CONTEXT, LoggingContext.class.getName() + "#getInstance");
- }
-
public static final String DEFAULT = "default";
@Target({METHOD})
diff --git a/java/com/google/gerrit/testing/FloggerInitializer.java b/java/com/google/gerrit/testing/FloggerInitializer.java
new file mode 100644
index 0000000..1972107
--- /dev/null
+++ b/java/com/google/gerrit/testing/FloggerInitializer.java
@@ -0,0 +1,31 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.testing;
+
+import com.google.gerrit.server.logging.LoggingContext;
+
+public class FloggerInitializer {
+ private static final String FLOGGER_BACKEND_PROPERTY = "flogger.backend_factory";
+ private static final String FLOGGER_LOGGING_CONTEXT = "flogger.logging_context";
+
+ private FloggerInitializer() {}
+
+ public static void initBackend() {
+ System.setProperty(
+ FLOGGER_BACKEND_PROPERTY,
+ "com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance");
+ System.setProperty(FLOGGER_LOGGING_CONTEXT, LoggingContext.class.getName() + "#getInstance");
+ }
+}
diff --git a/java/com/google/gerrit/testing/TestLoggingActivator.java b/java/com/google/gerrit/testing/TestLoggingActivator.java
index 2049bfd..a766429 100644
--- a/java/com/google/gerrit/testing/TestLoggingActivator.java
+++ b/java/com/google/gerrit/testing/TestLoggingActivator.java
@@ -83,6 +83,7 @@
public static void configureLogging() {
LogManager.resetConfiguration();
+ FloggerInitializer.initBackend();
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%-5p %c %x: %m%n");
@@ -99,4 +100,6 @@
LOG_LEVELS.entrySet().stream().forEach(e -> getLogger(e.getKey()).setLevel(e.getValue()));
}
+
+ private TestLoggingActivator() {}
}