mirror of
https://github.com/google/nomulus
synced 2026-08-16 12:16:09 +00:00
Rationalize logging statements across codebase
This fixes up the following problems: 1. Using string concatenation instead of the formatting variant methods. 2. Logging or swallowing exception messages without logging the exception itself (this swallows the stack trace). 3. Unnecessary logging on re-thrown exceptions. 4. Unnecessary use of formatting variant methods when not necessary. 5. Complicated logging statements involving significant processing not being wrapped inside of a logging level check. 6. Redundant logging both of an exception itself and its message (this is unnecessary duplication). 7. Use of the base Logger class instead of our FormattingLogger class. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=182419837
This commit is contained in:
@@ -82,7 +82,6 @@ public class BigqueryPollJobAction implements Runnable {
|
||||
try {
|
||||
task = (TaskOptions) new ObjectInputStream(new ByteArrayInputStream(payload)).readObject();
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
logger.severe(e, e.toString());
|
||||
throw new BadRequestException("Cannot deserialize task from payload", e);
|
||||
}
|
||||
String taskName = enqueuer.enqueue(getQueue(chainedQueueName.get()), task).getName();
|
||||
@@ -107,7 +106,7 @@ public class BigqueryPollJobAction implements Runnable {
|
||||
job = bigquery.jobs().get(projectId, jobId).execute();
|
||||
} catch (IOException e) {
|
||||
// We will throw a new exception because done==false, but first log this exception.
|
||||
logger.warning(e, e.getMessage());
|
||||
logger.warningfmt(e, "Error checking outcome of BigQuery job %s.", jobId);
|
||||
}
|
||||
// If job is not yet done, then throw an exception so that we'll return a failing HTTP status
|
||||
// code and the task will be retried.
|
||||
|
||||
@@ -121,10 +121,9 @@ public final class PublishDetailReportAction implements Runnable, JsonAction {
|
||||
throw new IllegalArgumentException(e.getMessage(), e);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.severe(e, e.toString());
|
||||
String message = firstNonNull(e.getMessage(), e.toString());
|
||||
throw e instanceof IllegalArgumentException
|
||||
? new BadRequestException(message) : new InternalServerErrorException(message);
|
||||
? new BadRequestException(message, e) : new InternalServerErrorException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class SyncGroupMembersAction implements Runnable {
|
||||
FAILED(SC_INTERNAL_SERVER_ERROR, "Error occurred while updating registrar contacts.") {
|
||||
@Override
|
||||
protected void log(Throwable cause) {
|
||||
logger.severefmt(cause, "%s", message);
|
||||
logger.severe(cause, message);
|
||||
}};
|
||||
|
||||
final int statusCode;
|
||||
@@ -79,7 +79,7 @@ public final class SyncGroupMembersAction implements Runnable {
|
||||
|
||||
/** Log an error message. Results that use log levels other than info should override this. */
|
||||
void log(@Nullable Throwable cause) {
|
||||
logger.infofmt(cause, "%s", message);
|
||||
logger.info(cause, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +90,7 @@ public final class SyncGroupMembersAction implements Runnable {
|
||||
@Inject SyncGroupMembersAction() {}
|
||||
|
||||
private void sendResponse(Result result, @Nullable List<Throwable> causes) {
|
||||
for (Throwable cause : nullToEmpty(causes)) {
|
||||
result.log(cause);
|
||||
}
|
||||
nullToEmpty(causes).forEach(result::log);
|
||||
response.setStatus(result.statusCode);
|
||||
response.setPayload(String.format("%s %s\n", result.name(), result.message));
|
||||
}
|
||||
|
||||
@@ -135,9 +135,8 @@ public class UpdateSnapshotViewAction implements Runnable {
|
||||
.build())));
|
||||
|
||||
logger.infofmt(
|
||||
"Updated view %s to point at snapshot table %s.",
|
||||
String.format("[%s:%s.%s]", projectId, viewDataset, kindName),
|
||||
String.format("[%s:%s.%s]", projectId, sourceDatasetId, sourceTableId));
|
||||
"Updated view [%s:%s.%s] to point at snapshot table [%s:%s.%s].",
|
||||
projectId, viewDataset, kindName, projectId, sourceDatasetId, sourceTableId);
|
||||
}
|
||||
|
||||
private static void updateTable(Bigquery bigquery, Table table) throws IOException {
|
||||
@@ -151,7 +150,8 @@ public class UpdateSnapshotViewAction implements Runnable {
|
||||
if (e.getDetails().getCode() == 404) {
|
||||
bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute();
|
||||
} else {
|
||||
logger.warningfmt("UpdateSnapshotViewAction failed, caught exception %s", e.getDetails());
|
||||
logger.warningfmt(
|
||||
e, "UpdateSnapshotViewAction failed, caught exception %s", e.getDetails());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,12 +74,12 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
||||
MISSINGNO(SC_BAD_REQUEST, "No sheet ID specified or configured; dropping task.") {
|
||||
@Override
|
||||
protected void log(Exception cause) {
|
||||
logger.warningfmt(cause, "%s", message);
|
||||
logger.warning(cause, message);
|
||||
}},
|
||||
FAILED(SC_INTERNAL_SERVER_ERROR, "Spreadsheet synchronization failed") {
|
||||
@Override
|
||||
protected void log(Exception cause) {
|
||||
logger.severefmt(cause, "%s", message);
|
||||
logger.severe(cause, message);
|
||||
}};
|
||||
|
||||
private final int statusCode;
|
||||
@@ -92,7 +92,7 @@ public class SyncRegistrarsSheetAction implements Runnable {
|
||||
|
||||
/** Log an error message. Results that use log levels other than info should override this. */
|
||||
protected void log(@Nullable Exception cause) {
|
||||
logger.infofmt(cause, "%s", message);
|
||||
logger.info(cause, message);
|
||||
}
|
||||
|
||||
private void send(Response response, @Nullable Exception cause) {
|
||||
|
||||
Reference in New Issue
Block a user