Migrate server classes to Flogger
This is the second part of the migration to Flogger. This change migrates all classes of the 'server' module to Flogger. Classes of the 'httpd' module have been migrated by the predecessor change. Other modules continue to use slf4j. They should be migrated by follow-up changes. During this migration we try to make the log statements more consistent: - avoid string concatenation - avoid usage of String.format(...) Change-Id: I233afc8360af7fef8640394204d0d676cc0d0001 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -16,6 +16,7 @@ package com.google.gerrit.server.permissions;
|
||||
|
||||
import static com.google.gerrit.server.permissions.DefaultPermissionMappings.globalPermission;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.annotations.CapabilityScope;
|
||||
import com.google.gerrit.extensions.annotations.RequiresAnyCapability;
|
||||
@@ -28,8 +29,6 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Global server permissions built into Gerrit. */
|
||||
public enum GlobalPermission implements GlobalOrPluginPermission {
|
||||
@@ -53,7 +52,7 @@ public enum GlobalPermission implements GlobalOrPluginPermission {
|
||||
VIEW_QUEUE,
|
||||
VIEW_ACCESS;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GlobalPermission.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
/**
|
||||
* Extracts the {@code @RequiresCapability} or {@code @RequiresAnyCapability} annotation.
|
||||
@@ -70,12 +69,13 @@ public enum GlobalPermission implements GlobalOrPluginPermission {
|
||||
RequiresCapability rc = findAnnotation(clazz, RequiresCapability.class);
|
||||
RequiresAnyCapability rac = findAnnotation(clazz, RequiresAnyCapability.class);
|
||||
if (rc != null && rac != null) {
|
||||
log.error(
|
||||
String.format(
|
||||
logger
|
||||
.atSevere()
|
||||
.log(
|
||||
"Class %s uses both @%s and @%s",
|
||||
clazz.getName(),
|
||||
RequiresCapability.class.getSimpleName(),
|
||||
RequiresAnyCapability.class.getSimpleName()));
|
||||
RequiresAnyCapability.class.getSimpleName());
|
||||
throw new PermissionBackendException("cannot extract permission");
|
||||
} else if (rc != null) {
|
||||
return Collections.singleton(
|
||||
@@ -124,17 +124,17 @@ public enum GlobalPermission implements GlobalOrPluginPermission {
|
||||
}
|
||||
|
||||
if (scope == CapabilityScope.PLUGIN) {
|
||||
log.error(
|
||||
String.format(
|
||||
logger
|
||||
.atSevere()
|
||||
.log(
|
||||
"Class %s uses @%s(scope=%s), but is not within a plugin",
|
||||
clazz.getName(), annotationClass.getSimpleName(), scope.name()));
|
||||
clazz.getName(), annotationClass.getSimpleName(), scope.name());
|
||||
throw new PermissionBackendException("cannot extract permission");
|
||||
}
|
||||
|
||||
Optional<GlobalPermission> perm = globalPermission(capability);
|
||||
if (!perm.isPresent()) {
|
||||
log.error(
|
||||
String.format("Class %s requires unknown capability %s", clazz.getName(), capability));
|
||||
logger.atSevere().log("Class %s requires unknown capability %s", clazz.getName(), capability);
|
||||
throw new PermissionBackendException("cannot extract permission");
|
||||
}
|
||||
return perm.get();
|
||||
|
||||
Reference in New Issue
Block a user