Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class CLIManager

public static final String COLOR = "color";

public static final String VERBOSE_LOGGERS = "XL";

/** This option is deprecated and may be repurposed as Java debug in a future version.
* Use {@code -X/--verbose} instead. */
@Deprecated
Expand All @@ -127,7 +129,7 @@ public CLIManager()
options.addOption( Option.builder( Character.toString( OFFLINE ) ).longOpt( "offline" ).desc( "Work offline" ).build() );
options.addOption( Option.builder( Character.toString( VERSION ) ).longOpt( "version" ).desc( "Display version information" ).build() );
options.addOption( Option.builder( Character.toString( QUIET ) ).longOpt( "quiet" ).desc( "Quiet output - only show errors" ).build() );
options.addOption( Option.builder( Character.toString( VERBOSE ) ).longOpt( "verbose" ).longOpt( "verbose" ).desc( "Produce execution verbose output" ).build() );
options.addOption( Option.builder( Character.toString( VERBOSE ) ).longOpt( "verbose" ).desc( "Produce execution verbose output" ).build() );
options.addOption( Option.builder( Character.toString( ERRORS ) ).longOpt( "errors" ).desc( "Produce execution error messages" ).build() );
options.addOption( Option.builder( Character.toString( NON_RECURSIVE ) ).longOpt( "non-recursive" ).desc( "Do not recurse into sub-projects. When used together with -pl, do not recurse into sub-projects of selected aggregators" ).build() );
options.addOption( Option.builder( Character.toString( UPDATE_SNAPSHOTS ) ).longOpt( "update-snapshots" ).desc( "Forces a check for missing releases and updated snapshots on remote repositories" ).build() );
Expand Down Expand Up @@ -158,6 +160,7 @@ public CLIManager()
options.addOption( Option.builder( BUILDER ).longOpt( "builder" ).hasArg().desc( "The id of the build strategy to use" ).build() );
options.addOption( Option.builder( NO_TRANSFER_PROGRESS ).longOpt( "no-transfer-progress" ).desc( "Do not display transfer progress when downloading or uploading" ).build() );
options.addOption( Option.builder().longOpt( COLOR ).hasArg().optionalArg( true ).desc( "Defines the color mode of the output. Supported are 'auto', 'always', 'never'." ).build() );
options.addOption( Option.builder( VERBOSE_LOGGERS ).longOpt( "verboseLoggers" ).hasArg().desc( "Produce verbose output for loggers (comma separated list of logger names)" ).build() );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sould be kebab case like other long options.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The desc should be similar to one of ACTIVATE_PROFILES, structurally.


// Deprecated
options.addOption( Option.builder().longOpt( DEBUG ).desc( "Produce execution verbose output (deprecated; only kept for backward compatibility)" ).build() );
Expand Down
13 changes: 13 additions & 0 deletions maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,19 @@ void logging( CliRequest cliRequest )
slf4jLoggerFactory = LoggerFactory.getILoggerFactory();
Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration( slf4jLoggerFactory );

String[] verboseLoggers = null;
if ( cliRequest.commandLine.hasOption( CLIManager.VERBOSE_LOGGERS ) )
{
verboseLoggers = cliRequest.commandLine.getOptionValues( CLIManager.VERBOSE_LOGGERS );
}
if ( verboseLoggers != null )
{
for ( String verboseLogger : verboseLoggers )
{
slf4jConfiguration.setLoggerLevel( verboseLogger, Slf4jConfiguration.Level.DEBUG );
}
}

if ( cliRequest.verbose )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should -X and -XL be mutually exclusive?

{
cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why any chance what this actually does? Since we cannot set it for the above?!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ public class BaseSlf4jConfiguration
{
private static final Logger LOGGER = LoggerFactory.getLogger( BaseSlf4jConfiguration.class );

@Override
public void setRootLoggerLevel( Level level )
{
LOGGER.warn( "setRootLoggerLevel: operation not supported" );
}

@Override
public void setLoggerLevel( final String loggerName, final Level level )
{
LOGGER.warn( "setLoggerLevel: operation not supported" );
}

@Override
public void activate()
{
LOGGER.warn( "reset(): operation not supported" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ enum Level
*/
void setRootLoggerLevel( Level level );

/**
* Set logging level for given logger name.

* @param loggerName the logger name.
* @param level the level.
*/
void setLoggerLevel( String loggerName, Level level );

/**
* Activate logging implementation configuration (if necessary).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class Log4j2Configuration
{
@Override
public void setRootLoggerLevel( Level level )
{
setLoggerLevel( "root", level );
}

@Override
public void setLoggerLevel( final String loggerName, final Level level )
{
String value;
switch ( level )
Expand All @@ -48,7 +54,7 @@ public void setRootLoggerLevel( Level level )
value = "error";
break;
}
System.setProperty( "maven.logging.root.level", value );
System.setProperty( "maven.logging." + loggerName + ".level", value );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I didn't even know that we have this. Why do we have it and why do we need it?

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.requireNonNull;

/**
* Configuration for slf4j-logback.
*
Expand All @@ -35,6 +37,14 @@ public class LogbackConfiguration
@Override
public void setRootLoggerLevel( Level level )
{
setLoggerLevel( Logger.ROOT_LOGGER_NAME, level );
}

@Override
public void setLoggerLevel( final String loggerName, final Level level )
{
requireNonNull( loggerName );
requireNonNull( level );
ch.qos.logback.classic.Level value;
switch ( level )
{
Expand All @@ -50,7 +60,7 @@ public void setRootLoggerLevel( Level level )
value = ch.qos.logback.classic.Level.ERROR;
break;
}
( (ch.qos.logback.classic.Logger) LoggerFactory.getLogger( Logger.ROOT_LOGGER_NAME ) ).setLevel( value );
( ( ch.qos.logback.classic.Logger ) LoggerFactory.getLogger( loggerName ) ).setLevel( value );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.slf4j.MavenSlf4jFriend;
import org.slf4j.impl.MavenSlf4jSimpleFriend;

import static java.util.Objects.requireNonNull;

/**
* Configuration for slf4j-simple.
*
Expand All @@ -35,6 +37,22 @@ public class Slf4jSimpleConfiguration
@Override
public void setRootLoggerLevel( Level level )
{
requireNonNull( level );
setSlf4jSimpleLoggerLevel( "defaultLogLevel", level );
}

@Override
public void setLoggerLevel( final String loggerName, final Level level )
{
requireNonNull( loggerName );
requireNonNull( level );
setSlf4jSimpleLoggerLevel( "log." + loggerName, level );
}

private void setSlf4jSimpleLoggerLevel( final String loggerName, final Level level )
{
requireNonNull( loggerName );
requireNonNull( level );
String value;
switch ( level )
{
Expand All @@ -50,7 +68,7 @@ public void setRootLoggerLevel( Level level )
value = "error";
break;
}
System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", value );
System.setProperty( "org.slf4j.simpleLogger." + loggerName, value );
}

@Override
Expand Down