Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Oct 7, 2024
1 parent fa0437b commit ee9d0b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/main/java/org/cryptomator/cli/CryptomatorCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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");
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/cryptomator/cli/LogbackConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class LogbackConfigurator extends ContextAwareBase implements Configurato

public static final AtomicReference<LogbackConfigurator> INSTANCE = new AtomicReference<>();

static final Map<String, Level> DEFAULT_LOG_LEVELS = Map.of( //
private static final Map<String, Level> 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<String, Level> DEBUG_LOG_LEVELS = Map.of( //
private static final Map<String, Level> DEBUG_LOG_LEVELS = Map.of( //
Logger.ROOT_LOGGER_NAME, Level.DEBUG, //
"org.cryptomator", Level.TRACE, //
"org.cryptomator.frontend.fuse.locks", Level.OFF
Expand Down Expand Up @@ -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<String, Level> logLevels) {
private void setLogLevels(Map<String, Level> logLevels) {
if (context instanceof LoggerContext lc) {
for (var loglevel : logLevels.entrySet()) {
Logger logger = lc.getLogger(loglevel.getKey());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cryptomator/cli/PasswordSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ee9d0b6

Please sign in to comment.