Migrate sshd classes to Flogger
This is the next part of the migration to Flogger. This change migrates all classes of the 'sshd' module to Flogger. Classes of the 'httpd', 'server' and 'restapi' modules have been migrated by predecessor changes. 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: I99d974697df8f7c817b1fcd3df642454a2e874b9 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -29,12 +29,12 @@ java_library(
|
||||
"//lib/bouncycastle:bcprov-neverlink",
|
||||
"//lib/commons:codec",
|
||||
"//lib/dropwizard:dropwizard-core",
|
||||
"//lib/flogger:api",
|
||||
"//lib/guice",
|
||||
"//lib/guice:guice-assistedinject",
|
||||
"//lib/guice:guice-servlet", # SSH should not depend on servlet
|
||||
"//lib/jgit/org.eclipse.jgit.archive:jgit-archive",
|
||||
"//lib/jgit/org.eclipse.jgit:jgit",
|
||||
"//lib/log:api",
|
||||
"//lib/log:log4j",
|
||||
"//lib/mina:core",
|
||||
"//lib/mina:sshd",
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.sshd;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.util.concurrent.Atomics;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
@@ -59,11 +60,10 @@ import org.apache.sshd.server.ExitCallback;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.CmdLineException;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class BaseCommand implements Command {
|
||||
private static final Logger log = LoggerFactory.getLogger(BaseCommand.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
public static final Charset ENC = UTF_8;
|
||||
|
||||
private static final int PRIVATE_STATUS = 1 << 30;
|
||||
@@ -351,7 +351,7 @@ public abstract class BaseCommand implements Command {
|
||||
}
|
||||
m.append(" during ");
|
||||
m.append(context.getCommandLine());
|
||||
log.error(m.toString(), e);
|
||||
logger.atSevere().withCause(e).log(m.toString());
|
||||
}
|
||||
|
||||
if (e instanceof Failure) {
|
||||
@@ -362,7 +362,7 @@ public abstract class BaseCommand implements Command {
|
||||
} catch (IOException e2) {
|
||||
// Ignored
|
||||
} catch (Throwable e2) {
|
||||
log.warn("Cannot send failure message to client", e2);
|
||||
logger.atWarning().withCause(e2).log("Cannot send failure message to client");
|
||||
}
|
||||
return f.exitCode;
|
||||
}
|
||||
@@ -373,7 +373,7 @@ public abstract class BaseCommand implements Command {
|
||||
} catch (IOException e2) {
|
||||
// Ignored
|
||||
} catch (Throwable e2) {
|
||||
log.warn("Cannot send internal server error message to client", e2);
|
||||
logger.atWarning().withCause(e2).log("Cannot send internal server error message to client");
|
||||
}
|
||||
return 128;
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.util.concurrent.Atomics;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
@@ -44,13 +45,11 @@ import org.apache.sshd.server.ExitCallback;
|
||||
import org.apache.sshd.server.SessionAware;
|
||||
import org.apache.sshd.server.session.ServerSession;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Creates a CommandFactory using commands registered by {@link CommandModule}. */
|
||||
@Singleton
|
||||
class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListener {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CommandFactoryProvider.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private final DispatchCommandProvider dispatcher;
|
||||
private final SshLog log;
|
||||
@@ -166,12 +165,12 @@ class CommandFactoryProvider implements Provider<CommandFactory>, LifecycleListe
|
||||
try {
|
||||
onStart();
|
||||
} catch (Exception e) {
|
||||
logger.warn(
|
||||
"Cannot start command \""
|
||||
+ ctx.getCommandLine()
|
||||
+ "\" for user "
|
||||
+ ctx.getSession().getUsername(),
|
||||
e);
|
||||
logger
|
||||
.atWarning()
|
||||
.withCause(e)
|
||||
.log(
|
||||
"Cannot start command \"%s\" for user %s",
|
||||
ctx.getCommandLine(), ctx.getSession().getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.FileUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.PeerDaemonUser;
|
||||
@@ -44,12 +45,10 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
|
||||
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
|
||||
import org.apache.sshd.server.session.ServerSession;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Authenticates by public key through {@link AccountSshKey} entities. */
|
||||
class DatabasePubKeyAuth implements PublickeyAuthenticator {
|
||||
private static final Logger log = LoggerFactory.getLogger(DatabasePubKeyAuth.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private final SshKeyCacheImpl sshKeyCache;
|
||||
private final SshLog sshLog;
|
||||
@@ -203,13 +202,13 @@ class DatabasePubKeyAuth implements PublickeyAuthenticator {
|
||||
} catch (NoSuchFileException noFile) {
|
||||
return Collections.emptySet();
|
||||
} catch (IOException err) {
|
||||
log.error("Cannot read " + path, err);
|
||||
logger.atSevere().withCause(err).log("Cannot read %s", path);
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
private static void logBadKey(Path path, String line, Exception e) {
|
||||
log.warn("Invalid key in " + path + ":\n " + line, e);
|
||||
logger.atWarning().withCause(e).log("Invalid key in %s:\n %s", path, line);
|
||||
}
|
||||
|
||||
boolean isCurrent() {
|
||||
|
@@ -21,6 +21,7 @@ import static org.apache.sshd.common.channel.ChannelOutputStream.WAIT_FOR_SPACE_
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.Version;
|
||||
import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.gerrit.metrics.Counter0;
|
||||
@@ -111,8 +112,6 @@ import org.apache.sshd.server.session.SessionFactory;
|
||||
import org.bouncycastle.crypto.prng.RandomGenerator;
|
||||
import org.bouncycastle.crypto.prng.VMPCRandomGenerator;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* SSH daemon to communicate with Gerrit.
|
||||
@@ -133,7 +132,7 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
@Singleton
|
||||
public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
private static final Logger sshDaemonLog = LoggerFactory.getLogger(SshDaemon.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
public enum SshSessionBackend {
|
||||
MINA,
|
||||
@@ -334,7 +333,7 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
throw new IllegalStateException("Cannot bind to " + addressList(), e);
|
||||
}
|
||||
|
||||
sshDaemonLog.info(String.format("Started Gerrit %s on %s", getVersion(), addressList()));
|
||||
logger.atInfo().log("Started Gerrit %s on %s", getVersion(), addressList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,9 +347,9 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
try {
|
||||
daemonAcceptor.close(true).await();
|
||||
shutdownExecutors();
|
||||
sshDaemonLog.info("Stopped Gerrit SSHD");
|
||||
logger.atInfo().log("Stopped Gerrit SSHD");
|
||||
} catch (IOException e) {
|
||||
sshDaemonLog.warn("Exception caught while closing", e);
|
||||
logger.atWarning().withCause(e).log("Exception caught while closing");
|
||||
} finally {
|
||||
daemonAcceptor = null;
|
||||
}
|
||||
@@ -400,9 +399,9 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
try {
|
||||
r.add(new HostKey(addr, keyBin));
|
||||
} catch (JSchException e) {
|
||||
sshDaemonLog.warn(
|
||||
String.format(
|
||||
"Cannot format SSHD host key [%s]: %s", pub.getAlgorithm(), e.getMessage()));
|
||||
logger
|
||||
.atWarning()
|
||||
.log("Cannot format SSHD host key [%s]: %s", pub.getAlgorithm(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -533,15 +532,14 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
final byte[] iv = new byte[c.getIVSize()];
|
||||
c.init(Cipher.Mode.Encrypt, key, iv);
|
||||
} catch (InvalidKeyException e) {
|
||||
sshDaemonLog.warn(
|
||||
"Disabling cipher "
|
||||
+ f.getName()
|
||||
+ ": "
|
||||
+ e.getMessage()
|
||||
+ "; try installing unlimited cryptography extension");
|
||||
logger
|
||||
.atWarning()
|
||||
.log(
|
||||
"Disabling cipher %s: %s; try installing unlimited cryptography extension",
|
||||
f.getName(), e.getMessage());
|
||||
i.remove();
|
||||
} catch (Exception e) {
|
||||
sshDaemonLog.warn("Disabling cipher " + f.getName() + ": " + e.getMessage());
|
||||
logger.atWarning().log("Disabling cipher %s: %s", f.getName(), e.getMessage());
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
@@ -602,7 +600,7 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
msg.append(avail[i].getName());
|
||||
}
|
||||
msg.append(" is supported");
|
||||
sshDaemonLog.error(msg.toString());
|
||||
logger.atSevere().log(msg.toString());
|
||||
} else if (add) {
|
||||
if (!def.contains(n)) {
|
||||
def.add(n);
|
||||
@@ -670,12 +668,13 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
List<NamedFactory<UserAuth>> authFactories = new ArrayList<>();
|
||||
if (kerberosKeytab != null) {
|
||||
authFactories.add(UserAuthGSSFactory.INSTANCE);
|
||||
sshDaemonLog.info("Enabling kerberos with keytab " + kerberosKeytab);
|
||||
logger.atInfo().log("Enabling kerberos with keytab %s", kerberosKeytab);
|
||||
if (!new File(kerberosKeytab).canRead()) {
|
||||
sshDaemonLog.error(
|
||||
"Keytab "
|
||||
+ kerberosKeytab
|
||||
+ " does not exist or is not readable; further errors are possible");
|
||||
logger
|
||||
.atSevere()
|
||||
.log(
|
||||
"Keytab %s does not exist or is not readable; further errors are possible",
|
||||
kerberosKeytab);
|
||||
}
|
||||
kerberosAuthenticator.setKeytabFile(kerberosKeytab);
|
||||
if (kerberosPrincipal == null) {
|
||||
@@ -685,11 +684,13 @@ public class SshDaemon extends SshServer implements SshInfo, LifecycleListener {
|
||||
kerberosPrincipal = "host/localhost";
|
||||
}
|
||||
}
|
||||
sshDaemonLog.info("Using kerberos principal " + kerberosPrincipal);
|
||||
logger.atInfo().log("Using kerberos principal %s", kerberosPrincipal);
|
||||
if (!kerberosPrincipal.startsWith("host/")) {
|
||||
sshDaemonLog.warn(
|
||||
"Host principal does not start with host/ "
|
||||
+ "which most SSH clients will supply automatically");
|
||||
logger
|
||||
.atWarning()
|
||||
.log(
|
||||
"Host principal does not start with host/ "
|
||||
+ "which most SSH clients will supply automatically");
|
||||
}
|
||||
kerberosAuthenticator.setServicePrincipalName(kerberosPrincipal);
|
||||
setGSSAuthenticator(kerberosAuthenticator);
|
||||
|
@@ -18,6 +18,7 @@ import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USE
|
||||
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.server.account.AccountSshKey;
|
||||
import com.google.gerrit.server.account.VersionedAuthorizedKeys;
|
||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||
@@ -38,13 +39,12 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Provides the {@link SshKeyCacheEntry}. */
|
||||
@Singleton
|
||||
public class SshKeyCacheImpl implements SshKeyCache {
|
||||
private static final Logger log = LoggerFactory.getLogger(SshKeyCacheImpl.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static final String CACHE_NAME = "sshkeys";
|
||||
|
||||
static final Iterable<SshKeyCacheEntry> NO_SUCH_USER = none();
|
||||
@@ -78,7 +78,7 @@ public class SshKeyCacheImpl implements SshKeyCache {
|
||||
try {
|
||||
return cache.get(username);
|
||||
} catch (ExecutionException e) {
|
||||
log.warn("Cannot load SSH keys for " + username, e);
|
||||
logger.atWarning().withCause(e).log("Cannot load SSH keys for %s", username);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -135,11 +135,13 @@ public class SshKeyCacheImpl implements SshKeyCache {
|
||||
|
||||
private void markInvalid(AccountSshKey k) {
|
||||
try {
|
||||
log.info("Flagging SSH key " + k.seq() + " of account " + k.accountId() + " invalid");
|
||||
logger.atInfo().log("Flagging SSH key %d of account %s invalid", k.seq(), k.accountId());
|
||||
authorizedKeys.markKeyInvalid(k.accountId(), k.seq());
|
||||
} catch (IOException | ConfigInvalidException e) {
|
||||
log.error(
|
||||
"Failed to mark SSH key " + k.seq() + " of account " + k.accountId() + " invalid", e);
|
||||
logger
|
||||
.atSevere()
|
||||
.withCause(e)
|
||||
.log("Failed to mark SSH key %d of account %s invalid", k.seq(), k.accountId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.errors.InvalidSshKeyException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.account.AccountSshKey;
|
||||
@@ -21,11 +22,9 @@ import com.google.gerrit.server.ssh.SshKeyCreator;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SshKeyCreatorImpl implements SshKeyCreator {
|
||||
private static final Logger log = LoggerFactory.getLogger(SshKeyCreatorImpl.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@Override
|
||||
public AccountSshKey create(Account.Id accountId, int seq, String encoded)
|
||||
@@ -38,7 +37,7 @@ public class SshKeyCreatorImpl implements SshKeyCreator {
|
||||
throw new InvalidSshKeyException();
|
||||
|
||||
} catch (NoSuchProviderException e) {
|
||||
log.error("Cannot parse SSH key", e);
|
||||
logger.atSevere().withCause(e).log("Cannot parse SSH key");
|
||||
throw new InvalidSshKeyException();
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
import com.google.gerrit.server.DynamicOptions;
|
||||
import com.google.gerrit.server.plugins.Plugin;
|
||||
@@ -24,12 +25,10 @@ import com.google.inject.Key;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import org.apache.sshd.server.Command;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Singleton
|
||||
class SshPluginStarterCallback implements StartPluginListener, ReloadPluginListener {
|
||||
private static final Logger log = LoggerFactory.getLogger(SshPluginStarterCallback.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private final DispatchCommandProvider root;
|
||||
private final DynamicMap<DynamicOptions.DynamicBean> dynamicBeans;
|
||||
@@ -65,11 +64,12 @@ class SshPluginStarterCallback implements StartPluginListener, ReloadPluginListe
|
||||
return plugin.getSshInjector().getProvider(key);
|
||||
} catch (RuntimeException err) {
|
||||
if (!providesDynamicOptions(plugin)) {
|
||||
log.warn(
|
||||
String.format(
|
||||
logger
|
||||
.atWarning()
|
||||
.withCause(err)
|
||||
.log(
|
||||
"Plugin %s did not define its top-level command nor any DynamicOptions",
|
||||
plugin.getName()),
|
||||
err);
|
||||
plugin.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.sshd.commands;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.common.ProjectInfo;
|
||||
@@ -42,8 +43,6 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
|
||||
@CommandMetaData(
|
||||
@@ -51,7 +50,7 @@ import org.slf4j.LoggerFactory;
|
||||
description = "Change the project permissions are inherited from"
|
||||
)
|
||||
final class AdminSetParent extends SshCommand {
|
||||
private static final Logger log = LoggerFactory.getLogger(AdminSetParent.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@Option(
|
||||
name = "--parent",
|
||||
@@ -172,7 +171,7 @@ final class AdminSetParent extends SshCommand {
|
||||
err.append("error: Project ").append(name).append(" not found\n");
|
||||
} catch (IOException | ConfigInvalidException e) {
|
||||
final String msg = "Cannot update project " + name;
|
||||
log.error(msg, e);
|
||||
logger.atSevere().withCause(e).log(msg);
|
||||
err.append("error: ").append(msg).append("\n");
|
||||
}
|
||||
|
||||
@@ -180,7 +179,7 @@ final class AdminSetParent extends SshCommand {
|
||||
projectCache.evict(nameKey);
|
||||
} catch (IOException e) {
|
||||
final String msg = "Cannot reindex project: " + name;
|
||||
log.error(msg, e);
|
||||
logger.atSevere().withCause(e).log(msg);
|
||||
err.append("error: ").append(msg).append("\n");
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.sshd.commands;
|
||||
|
||||
import static com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.sshd.AdminHighPriorityCommand;
|
||||
@@ -33,8 +34,6 @@ import org.apache.sshd.common.io.IoSession;
|
||||
import org.apache.sshd.common.session.helpers.AbstractSession;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Close specified SSH connections */
|
||||
@AdminHighPriorityCommand
|
||||
@@ -45,8 +44,7 @@ import org.slf4j.LoggerFactory;
|
||||
runsAt = MASTER_OR_SLAVE
|
||||
)
|
||||
final class CloseConnection extends SshCommand {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CloseConnection.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@Inject private SshDaemon sshDaemon;
|
||||
|
||||
@@ -84,7 +82,9 @@ final class CloseConnection extends SshCommand {
|
||||
future.await();
|
||||
stdout.println("closed connection " + sessionId);
|
||||
} catch (IOException e) {
|
||||
log.warn("Wait for connection to close interrupted: " + e.getMessage());
|
||||
logger
|
||||
.atWarning()
|
||||
.log("Wait for connection to close interrupted: %s", e.getMessage());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.sshd.commands;
|
||||
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.common.collect.SetMultimap;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.data.Capable;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -41,8 +42,6 @@ import org.eclipse.jgit.lib.RefDatabase;
|
||||
import org.eclipse.jgit.transport.AdvertiseRefsHook;
|
||||
import org.eclipse.jgit.transport.ReceivePack;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Receives change upload over SSH using the Git receive-pack protocol. */
|
||||
@CommandMetaData(
|
||||
@@ -50,7 +49,7 @@ import org.slf4j.LoggerFactory;
|
||||
description = "Standard Git server side command for client side git push"
|
||||
)
|
||||
final class Receive extends AbstractGitCommand {
|
||||
private static final Logger log = LoggerFactory.getLogger(Receive.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@Inject private AsyncReceiveCommits.Factory factory;
|
||||
@Inject private IdentifiedUser currentUser;
|
||||
@@ -121,7 +120,7 @@ final class Receive extends AbstractGitCommand {
|
||||
msg.append(currentUser.getAccountId());
|
||||
msg.append("): ");
|
||||
msg.append(badStream.getCause().getMessage());
|
||||
log.info(msg.toString());
|
||||
logger.atInfo().log(msg.toString());
|
||||
throw new UnloggedFailure(128, "error: " + badStream.getCause().getMessage());
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.sshd.commands;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelValue;
|
||||
@@ -53,12 +54,10 @@ import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@CommandMetaData(name = "review", description = "Apply reviews to one or more patch sets")
|
||||
public class ReviewCommand extends SshCommand {
|
||||
private static final Logger log = LoggerFactory.getLogger(ReviewCommand.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@Override
|
||||
protected final CmdLineParser newCmdLineParser(Object options) {
|
||||
@@ -231,7 +230,7 @@ public class ReviewCommand extends SshCommand {
|
||||
} catch (Exception e) {
|
||||
ok = false;
|
||||
writeError("fatal", "internal server error while reviewing " + patchSet.getId() + "\n");
|
||||
log.error("internal error while reviewing " + patchSet.getId(), e);
|
||||
logger.atSevere().withCause(e).log("internal error while reviewing %s", patchSet.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -24,6 +24,7 @@ package com.google.gerrit.sshd.commands;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.server.tools.ToolsCatalog;
|
||||
import com.google.gerrit.server.tools.ToolsCatalog.Entry;
|
||||
import com.google.gerrit.sshd.BaseCommand;
|
||||
@@ -33,13 +34,12 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
final class ScpCommand extends BaseCommand {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static final String TYPE_DIR = "D";
|
||||
private static final String TYPE_FILE = "C";
|
||||
private static final Logger log = LoggerFactory.getLogger(ScpCommand.class);
|
||||
|
||||
private boolean opt_r;
|
||||
private boolean opt_t;
|
||||
@@ -137,7 +137,7 @@ final class ScpCommand extends BaseCommand {
|
||||
} catch (IOException e2) {
|
||||
// Ignore
|
||||
}
|
||||
log.debug("Error in scp command", e);
|
||||
logger.atFine().withCause(e).log("Error in scp command");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ final class ScpCommand extends BaseCommand {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
log.debug("Received warning: " + readLine());
|
||||
logger.atFine().log("Received warning: %s", readLine());
|
||||
break;
|
||||
case 2:
|
||||
throw new IOException("Received nack: " + readLine());
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.sshd.commands;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||
import com.google.gerrit.extensions.api.changes.DeleteReviewerInput;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
@@ -39,12 +40,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@CommandMetaData(name = "set-reviewers", description = "Add or remove reviewers on a change")
|
||||
public class SetReviewersCommand extends SshCommand {
|
||||
private static final Logger log = LoggerFactory.getLogger(SetReviewersCommand.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@Option(name = "--project", aliases = "-p", usage = "project containing the change")
|
||||
private ProjectState projectState;
|
||||
@@ -106,7 +105,7 @@ public class SetReviewersCommand extends SshCommand {
|
||||
ok &= modifyOne(rsrc);
|
||||
} catch (Exception err) {
|
||||
ok = false;
|
||||
log.error("Error updating reviewers on change " + rsrc.getId(), err);
|
||||
logger.atSevere().withCause(err).log("Error updating reviewers on change %s", rsrc.getId());
|
||||
writeError("fatal", "internal error while updating " + rsrc.getId());
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.sshd.commands;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.common.data.GlobalCapability;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
@@ -45,13 +46,11 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import org.apache.sshd.server.Environment;
|
||||
import org.kohsuke.args4j.Option;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@RequiresCapability(GlobalCapability.STREAM_EVENTS)
|
||||
@CommandMetaData(name = "stream-events", description = "Monitor events occurring in real time")
|
||||
final class StreamEvents extends BaseCommand {
|
||||
private static final Logger log = LoggerFactory.getLogger(StreamEvents.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
/** Maximum number of events that may be queued up for each connection. */
|
||||
private static final int MAX_EVENTS = 128;
|
||||
@@ -279,7 +278,7 @@ final class StreamEvents extends BaseCommand {
|
||||
try {
|
||||
msg = gson.toJson(message) + "\n";
|
||||
} catch (Exception e) {
|
||||
log.warn("Could not deserialize the msg: ", e);
|
||||
logger.atWarning().withCause(e).log("Could not deserialize the msg");
|
||||
}
|
||||
if (msg != null) {
|
||||
synchronized (stdout) {
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.sshd.plugin;
|
||||
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.extensions.registration.DynamicItem;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
@@ -24,11 +25,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.kohsuke.args4j.Argument;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LfsPluginAuthCommand extends SshCommand {
|
||||
private static final Logger log = LoggerFactory.getLogger(LfsPluginAuthCommand.class);
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
private static final String CONFIGURATION_ERROR =
|
||||
"Server configuration error: LFS auth over SSH is not properly configured.";
|
||||
|
||||
@@ -67,7 +67,7 @@ public class LfsPluginAuthCommand extends SshCommand {
|
||||
protected void run() throws UnloggedFailure, Exception {
|
||||
LfsSshPluginAuth pluginAuth = auth.get();
|
||||
if (pluginAuth == null) {
|
||||
log.warn(CONFIGURATION_ERROR);
|
||||
logger.atWarning().log(CONFIGURATION_ERROR);
|
||||
throw new UnloggedFailure(1, CONFIGURATION_ERROR);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user