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:
Edwin Kempin
2018-05-04 11:50:06 +02:00
parent 03d2d209b1
commit a655fe03a7
195 changed files with 1513 additions and 1514 deletions

View File

@@ -22,6 +22,7 @@ import static com.google.gerrit.reviewdb.client.RefNames.REFS_USERS_SELF;
import static java.util.stream.Collectors.toMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.reviewdb.client.Account;
@@ -60,11 +61,9 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.SymbolicRef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class DefaultRefFilter {
private static final Logger log = LoggerFactory.getLogger(DefaultRefFilter.class);
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
interface Factory {
DefaultRefFilter create(ProjectControl projectControl);
@@ -286,7 +285,10 @@ class DefaultRefFilter {
} catch (AuthException e) {
return false;
} catch (PermissionBackendException e) {
log.error("Failed to check permission for " + id + " in " + projectState.getName(), e);
logger
.atSevere()
.withCause(e)
.log("Failed to check permission for %s in %s", id, projectState.getName());
return false;
}
}
@@ -306,8 +308,10 @@ class DefaultRefFilter {
}
return visibleChanges;
} catch (OrmException | PermissionBackendException e) {
log.error(
"Cannot load changes for project " + project + ", assuming no changes are visible", e);
logger
.atSevere()
.withCause(e)
.log("Cannot load changes for project %s, assuming no changes are visible", project);
return Collections.emptyMap();
}
}
@@ -318,7 +322,10 @@ class DefaultRefFilter {
try {
s = changeNotesFactory.scan(repo, db.get(), p);
} catch (IOException e) {
log.error("Cannot load changes for project " + p + ", assuming no changes are visible", e);
logger
.atSevere()
.withCause(e)
.log("Cannot load changes for project %s, assuming no changes are visible", p);
return Collections.emptyMap();
}
return s.map(this::toNotes)
@@ -329,8 +336,10 @@ class DefaultRefFilter {
@Nullable
private ChangeNotes toNotes(ChangeNotesResult r) {
if (r.error().isPresent()) {
log.warn(
"Failed to load change " + r.id() + " in " + projectState.getName(), r.error().get());
logger
.atWarning()
.withCause(r.error().get())
.log("Failed to load change %s in %s", r.id(), projectState.getName());
return null;
}
try {
@@ -339,7 +348,10 @@ class DefaultRefFilter {
return r.notes();
}
} catch (PermissionBackendException e) {
log.error("Failed to check permission for " + r.id() + " in " + projectState.getName(), e);
logger
.atSevere()
.withCause(e)
.log("Failed to check permission for %s in %s", r.id(), projectState.getName());
}
return null;
}
@@ -362,7 +374,7 @@ class DefaultRefFilter {
} catch (AuthException e) {
return false;
} catch (PermissionBackendException e) {
log.error("unable to check permissions", e);
logger.atSevere().withCause(e).log("unable to check permissions");
return false;
}
return projectState.statePermitsRead();
@@ -375,10 +387,10 @@ class DefaultRefFilter {
} catch (AuthException e) {
return false;
} catch (PermissionBackendException e) {
log.error(
String.format(
"Can't check permission for user %s on project %s", user, projectState.getName()),
e);
logger
.atSevere()
.withCause(e)
.log("Can't check permission for user %s on project %s", user, projectState.getName());
return false;
}
return true;