Merge branch 'stable-3.0' into stable-3.1

* stable-3.0:
  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: I34c5e8463a6f278ca137aab1ffd2b50172eaff20
This commit is contained in:
David Pursehouse
2020-05-04 15:32:32 +09:00
4 changed files with 36 additions and 14 deletions

View File

@@ -144,8 +144,7 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log
} }
boolean isLoggingForced() { boolean isLoggingForced() {
Boolean force = forceLogging.get(); return Boolean.TRUE.equals(forceLogging.get());
return force != null ? force : false;
} }
boolean forceLogging(boolean force) { boolean forceLogging(boolean force) {
@@ -155,7 +154,7 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log
} else { } else {
forceLogging.remove(); forceLogging.remove();
} }
return oldValue != null ? oldValue : false; return Boolean.TRUE.equals(oldValue);
} }
boolean isPerformanceLogging() { boolean isPerformanceLogging() {

View File

@@ -24,7 +24,6 @@ import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gerrit.server.logging.LoggingContext;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.Target; import java.lang.annotation.Target;
@@ -107,16 +106,6 @@ import org.junit.runners.model.InitializationError;
* field annotated with {@code @ConfigSuite.Name}. * field annotated with {@code @ConfigSuite.Name}.
*/ */
public class ConfigSuite extends Suite { 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"; public static final String DEFAULT = "default";
@Target({METHOD}) @Target({METHOD})

View File

@@ -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");
}
}

View File

@@ -83,6 +83,7 @@ public class TestLoggingActivator {
public static void configureLogging() { public static void configureLogging() {
LogManager.resetConfiguration(); LogManager.resetConfiguration();
FloggerInitializer.initBackend();
PatternLayout layout = new PatternLayout(); PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%-5p %c %x: %m%n"); layout.setConversionPattern("%-5p %c %x: %m%n");
@@ -99,4 +100,6 @@ public class TestLoggingActivator {
LOG_LEVELS.entrySet().stream().forEach(e -> getLogger(e.getKey()).setLevel(e.getValue())); LOG_LEVELS.entrySet().stream().forEach(e -> getLogger(e.getKey()).setLevel(e.getValue()));
} }
private TestLoggingActivator() {}
} }