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:
mcilwain 2018-01-18 12:27:06 -08:00 committed by Ben McIlwain
parent f22a42cd42
commit 81dc2bbbc3
47 changed files with 172 additions and 154 deletions

View file

@ -16,6 +16,7 @@ package google.registry.testing.sftp;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.util.FormattingLogger;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
@ -23,8 +24,6 @@ import java.security.KeyPair;
import java.security.PublicKey;
import java.security.Security;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.ftplet.FtpException;
@ -48,7 +47,7 @@ import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
/** In-process SFTP server using Apache SSHD. */
public class TestSftpServer implements FtpServer {
private static final Logger logger = Logger.getLogger(TestSftpServer.class.getName());
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static SingletonRandomFactory secureRandomFactory;
@ -94,10 +93,10 @@ public class TestSftpServer implements FtpServer {
try (PEMParser pemParser = new PEMParser(new StringReader(key))) {
PEMKeyPair pemPair = (PEMKeyPair) pemParser.readObject();
KeyPair result = new JcaPEMKeyConverter().setProvider("BC").getKeyPair(pemPair);
logger.info("Read key pair " + result);
logger.infofmt("Read key pair %s", result);
return result;
} catch (IOException e) {
logger.log(Level.SEVERE, "Couldn't read key pair from string(!)", e);
logger.severe(e, "Couldn't read key pair from string.");
return null;
}
}
@ -190,7 +189,7 @@ public class TestSftpServer implements FtpServer {
server.stop(true);
stopped = true;
} catch (IOException e) {
logger.log(Level.WARNING, "Error shutting down server", e);
logger.warning(e, "Error shutting down server");
}
}
@ -201,7 +200,6 @@ public class TestSftpServer implements FtpServer {
server.start();
stopped = false;
} catch (IOException e) {
logger.log(Level.WARNING, "Couldn't start server", e);
throw new FtpException("Couldn't start server", e);
}
}