Skip to content

Commit

Permalink
JBEAP-26480: add --debug option to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
michpetrov committed Feb 7, 2024
1 parent e09006e commit 8fe7967
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ logger.level=INFO
# Declare handlers for the root logger
logger.handlers=FILE

handlers=CONSOLE,FILE
# Console handler configuration
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush
Expand Down
18 changes: 18 additions & 0 deletions prospero-cli/src/main/java/org/wildfly/prospero/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
package org.wildfly.prospero.cli;

import org.jboss.logging.Logger;
import org.jboss.logmanager.Configurator;
import org.jboss.logmanager.Level;
import org.jboss.logmanager.PropertyConfigurator;
import org.jboss.logmanager.config.LogContextConfiguration;
import org.wildfly.prospero.cli.commands.ChannelCommand;
import org.wildfly.prospero.cli.commands.CliConstants;
import org.wildfly.prospero.cli.commands.CloneCommand;
Expand Down Expand Up @@ -105,6 +109,20 @@ public static CommandLine createCommandLine(CliConsole console, String[] args, A

commandLine.setParameterExceptionHandler(new UnknownCommandParameterExceptionHandler(rootParameterExceptionHandler, System.err));

final boolean isDebug = Arrays.stream(args).anyMatch(CliConstants.DEBUG::equals);
if (isDebug) {
Configurator c = org.jboss.logmanager.Logger.getLogger("").getAttachment(Configurator.ATTACHMENT_KEY);
if (c instanceof PropertyConfigurator) {
LogContextConfiguration lcc = ((PropertyConfigurator) c).getLogContextConfiguration();
lcc.getLoggerConfiguration("org.wildfly.prospero").setLevel(Level.DEBUG.getName());
lcc.getLoggerConfiguration("org.wildfly.prospero").addHandlerName("CONSOLE");
lcc.getHandlerConfiguration("CONSOLE").setLevel(Level.DEBUG.getName());
lcc.commit();
} else {
logger.warn("Cannot change logging level, using default.");
}
}

return commandLine;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public abstract class AbstractCommand implements Callable<Integer> {
)
boolean verbose;

@SuppressWarnings("unused")
@CommandLine.Option(
names = {CliConstants.DEBUG},
order = 102
)
boolean debug;

public AbstractCommand(CliConsole console, ActionFactory actionFactory) {
this.console = console;
this.actionFactory = actionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private Commands() {
public static final String VERSION = "--version";
public static final String VV = "-vv";
public static final String VERBOSE = "--verbose";
public static final String DEBUG = "--debug";
public static final String Y = "-y";
public static final String YES = "--yes";

Expand Down
2 changes: 2 additions & 0 deletions prospero-cli/src/main/resources/UsageMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ help = Displays the help information for this command.
${prospero.dist.name}.help = Displays the help information for the command.
verbose = Prints additional information if the command fails.
${prospero.dist.name}.verbose = Prints additional information if the command fails.
debug = Prints debug messages.
${prospero.dist.name}.debug = Prints debug messages.
local-cache = Path to the local Maven repository cache. It overrides the default Maven repository at ~/.m2/repository.
no-resolve-local-cache.0 = Perform the operation without resolving or installing artifacts in the local maven cache.
no-resolve-local-cache.1 = WARNING: Deprecated, please see --use-default-local-cache for alternatives.
Expand Down
1 change: 1 addition & 0 deletions prospero-cli/src/main/resources/logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ logger.level=ERROR
# Declare handlers for the root logger
logger.handlers=CONSOLE

handlers=CONSOLE
# Console handler configuration
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush
Expand Down

0 comments on commit 8fe7967

Please sign in to comment.