diff --git a/src/main/java/org/cryptomator/cli/CryptomatorCli.java b/src/main/java/org/cryptomator/cli/CryptomatorCli.java index e982f24..cd1856f 100644 --- a/src/main/java/org/cryptomator/cli/CryptomatorCli.java +++ b/src/main/java/org/cryptomator/cli/CryptomatorCli.java @@ -63,13 +63,7 @@ void setMaxCleartextNameLength(int input) { @Override public Integer call() throws Exception { if (verbose) { - var logConfigurator = LogbackConfigurator.INSTANCE.get(); - if (logConfigurator != null) { - logConfigurator.setLogLevels(LogbackConfigurator.DEBUG_LOG_LEVELS); - LOG.debug("User verbose logging"); - } else { - throw new IllegalStateException("Logging is not configured."); - } + activateVerboseMode(); } csprng = SecureRandom.getInstanceStrong(); @@ -99,6 +93,15 @@ public Integer call() throws Exception { return 0; } + private void activateVerboseMode() { + var logConfigurator = LogbackConfigurator.INSTANCE.get(); + if (logConfigurator == null) { + throw new IllegalStateException("Logging is not configured."); + } + logConfigurator.switchToDebug(); + LOG.debug("Activated debug logging"); + } + private Masterkey loadMasterkey(URI keyId) { try (var passphraseContainer = passwordSource.readPassphrase()) { Path filePath = pathToVault.resolve("masterkey.cryptomator"); diff --git a/src/main/java/org/cryptomator/cli/LogbackConfigurator.java b/src/main/java/org/cryptomator/cli/LogbackConfigurator.java index e75f33e..410e0c9 100644 --- a/src/main/java/org/cryptomator/cli/LogbackConfigurator.java +++ b/src/main/java/org/cryptomator/cli/LogbackConfigurator.java @@ -18,13 +18,13 @@ public class LogbackConfigurator extends ContextAwareBase implements Configurato public static final AtomicReference INSTANCE = new AtomicReference<>(); - static final Map DEFAULT_LOG_LEVELS = Map.of( // + private static final Map DEFAULT_LOG_LEVELS = Map.of( // Logger.ROOT_LOGGER_NAME, Level.INFO, // "org.cryptomator", Level.INFO, // "org.cryptomator.frontend.fuse.locks", Level.OFF ); - public static final Map DEBUG_LOG_LEVELS = Map.of( // + private static final Map DEBUG_LOG_LEVELS = Map.of( // Logger.ROOT_LOGGER_NAME, Level.DEBUG, // "org.cryptomator", Level.TRACE, // "org.cryptomator.frontend.fuse.locks", Level.OFF @@ -57,12 +57,16 @@ public ExecutionStatus configure(LoggerContext context) { return ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY; } + void switchToDebug() { + setLogLevels(DEBUG_LOG_LEVELS); + } + /** * Adjust the log levels * * @param logLevels new log levels to use */ - public void setLogLevels(Map logLevels) { + private void setLogLevels(Map logLevels) { if (context instanceof LoggerContext lc) { for (var loglevel : logLevels.entrySet()) { Logger logger = lc.getLogger(loglevel.getKey()); diff --git a/src/main/java/org/cryptomator/cli/PasswordSource.java b/src/main/java/org/cryptomator/cli/PasswordSource.java index 6a68bb4..2d4ce93 100644 --- a/src/main/java/org/cryptomator/cli/PasswordSource.java +++ b/src/main/java/org/cryptomator/cli/PasswordSource.java @@ -34,7 +34,7 @@ Passphrase readPassphrase() throws IOException { } else if (passphraseFile != null) { return readPassphraseFromFile(); } - throw new IllegalStateException("Passphrase location not specified, but required."); + throw new IllegalStateException("Passphrase source not specified, but required."); } private Passphrase readPassphraseFromStdin() {