Updated Branches: refs/heads/logging/slf4j-jul [created] cb69308a8
Basic experiment with JUL. - Should be the same as 7f9e280522379fc0f3ac09f4d81e8188cdb54192 only with JUL as the backing impl Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/cb69308a Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/cb69308a Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/cb69308a Branch: refs/heads/logging/slf4j-jul Commit: cb69308a848105c0c28d49bdf126008ea5304a4d Parents: c8536bf Author: Stephen Connolly <stephen.alan.conno...@gmail.com> Authored: Wed Dec 12 10:34:52 2012 +0000 Committer: Stephen Connolly <stephen.alan.conno...@gmail.com> Committed: Wed Dec 12 10:34:52 2012 +0000 ---------------------------------------------------------------------- apache-maven/pom.xml | 3 +- .../src/conf/logging/simplelogger.properties | 8 - build.xml | 2 +- maven-embedder/pom.xml | 7 +- .../main/java/org/apache/maven/cli/MavenCli.java | 175 ++++++++++----- pom.xml | 4 +- 6 files changed, 126 insertions(+), 73 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/cb69308a/apache-maven/pom.xml ---------------------------------------------------------------------- diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index ce547e7..b2c06d3 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -85,7 +85,8 @@ </dependency> <dependency> <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.7.2</version> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/maven/blob/cb69308a/apache-maven/src/conf/logging/simplelogger.properties ---------------------------------------------------------------------- diff --git a/apache-maven/src/conf/logging/simplelogger.properties b/apache-maven/src/conf/logging/simplelogger.properties deleted file mode 100644 index cd11ce1..0000000 --- a/apache-maven/src/conf/logging/simplelogger.properties +++ /dev/null @@ -1,8 +0,0 @@ -org.slf4j.simpleLogger.defaultLogLevel=info -org.slf4j.simpleLogger.showDateTime=false -org.slf4j.simpleLogger.showThreadName=false -org.slf4j.simpleLogger.showLogName=false -org.slf4j.simpleLogger.logFile=System.out -org.slf4j.simpleLogger.levelInBrackets=true -org.slf4j.simpleLogger.log.Sisu=info -org.slf4j.simpleLogger.warnLevelString=WARNING \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven/blob/cb69308a/build.xml ---------------------------------------------------------------------- diff --git a/build.xml b/build.xml index 4bbbec9..d978b25 100644 --- a/build.xml +++ b/build.xml @@ -34,7 +34,7 @@ END SNIPPET: ant-bootstrap --> <property name="distributionDirectory" value="apache-maven"/> <property name="distributionId" value="apache-maven"/> <property name="distributionShortName" value="Maven"/> - <property name="distributionName" value="Apache Maven"/> + <property name="distributionName" value="Apache Maven (java.util.logging)"/> <property name="it.workdir.version" value="3.0.x" /> <target name="initTaskDefs"> http://git-wip-us.apache.org/repos/asf/maven/blob/cb69308a/maven-embedder/pom.xml ---------------------------------------------------------------------- diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 587398f..e282b46 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -10,7 +10,8 @@ governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -74,6 +75,10 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + </dependency> <!-- CLI --> <dependency> <groupId>commons-cli</groupId> http://git-wip-us.apache.org/repos/asf/maven/blob/cb69308a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java ---------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index e744e65..c642fd5 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -23,6 +23,9 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; @@ -30,6 +33,12 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; +import java.util.logging.ConsoleHandler; +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.SimpleFormatter; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.ParseException; @@ -116,9 +125,9 @@ public class MavenCli private LoggerManager plexusLoggerManager; private ILoggerFactory slf4jLoggerFactory; - + private Logger slf4jLogger; - + private EventSpyDispatcher eventSpyDispatcher; private ModelProcessor modelProcessor; @@ -263,7 +272,8 @@ public class MavenCli throws Exception { // - // Parsing errors can happen during the processing of the arguments and we prefer not having to check if the logger is null + // Parsing errors can happen during the processing of the arguments and we prefer not having to check if the + // logger is null // and construct this so we can use an SLF4J logger everywhere. // slf4jLogger = new Slf4jStdoutLogger(); @@ -292,7 +302,7 @@ public class MavenCli System.out.println( CLIReportingUtils.showVersion() ); throw new ExitException( 0 ); } - } + } // // All logging is handled by SFL4J @@ -306,24 +316,23 @@ public class MavenCli if ( cliRequest.debug ) { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "debug" ); + setRootLoggerLevel( Level.FINEST ); } else if ( cliRequest.quiet ) { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_ERROR ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "error" ); + setRootLoggerLevel( Level.SEVERE ); } else { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_INFO ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "info" ); + setRootLoggerLevel( Level.INFO ); } if ( cliRequest.commandLine.hasOption( CLIManager.LOG_FILE ) ) { File logFile = new File( cliRequest.commandLine.getOptionValue( CLIManager.LOG_FILE ) ); logFile = resolveFile( logFile, cliRequest.workingDirectory ); - System.setProperty( "org.slf4j.simpleLogger.logFile", logFile.getAbsolutePath() ); try { PrintStream ps = new PrintStream( new FileOutputStream( logFile ) ); @@ -343,6 +352,47 @@ public class MavenCli slf4jLogger = slf4jLoggerFactory.getLogger( this.getClass().getName() ); } + public void setRootLoggerLevel( Level level ) + { + java.util.logging.ConsoleHandler consoleHandler = new ConsoleHandler(); + consoleHandler.setLevel( level ); + consoleHandler.setFormatter( new Formatter() + { + private String lineSeparator = System.getProperty( "line.separator" ); + + @Override + public String format( LogRecord record ) + { + StringBuilder sb = new StringBuilder(); + sb.append( '[' ); + sb.append( record.getLevel().getLocalizedName() ); + sb.append( "] " ); + sb.append( formatMessage( record ) ); + sb.append( lineSeparator ); + if ( record.getThrown() != null ) + { + try + { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter( sw ); + record.getThrown().printStackTrace( pw ); + pw.close(); + sb.append( sw.toString() ); + } + catch ( Exception ex ) + { + } + } + return sb.toString(); + } + } ); + java.util.logging.Logger logger = java.util.logging.Logger.getLogger( "" ); + for ( Handler h : logger.getHandlers() ) { + logger.removeHandler( h ); + } + logger.addHandler( consoleHandler ); + } + private void version( CliRequest cliRequest ) { if ( cliRequest.debug || cliRequest.commandLine.hasOption( CLIManager.SHOW_VERSION ) ) @@ -383,29 +433,25 @@ public class MavenCli DefaultPlexusContainer container = null; - ContainerConfiguration cc = new DefaultContainerConfiguration() - .setClassWorld( cliRequest.classWorld ) - .setRealm( setupContainerRealm( cliRequest ) ) - .setClassPathScanning( PlexusConstants.SCANNING_INDEX ) - .setAutoWiring( true ) - .setName( "maven" ); + ContainerConfiguration cc = + new DefaultContainerConfiguration().setClassWorld( cliRequest.classWorld ).setRealm( setupContainerRealm( cliRequest ) ).setClassPathScanning( PlexusConstants.SCANNING_INDEX ).setAutoWiring( true ).setName( "maven" ); - container = new DefaultPlexusContainer( cc, new AbstractModule() - { + container = new DefaultPlexusContainer( cc, new AbstractModule() + { - protected void configure() - { - bind( ILoggerFactory.class ).toInstance( slf4jLoggerFactory ); - } + protected void configure() + { + bind( ILoggerFactory.class ).toInstance( slf4jLoggerFactory ); + } - } ); + } ); - // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups - container.setLookupRealm( null ); + // NOTE: To avoid inconsistencies, we'll use the TCCL exclusively for lookups + container.setLookupRealm( null ); - container.setLoggerManager( plexusLoggerManager ); + container.setLoggerManager( plexusLoggerManager ); - customizeContainer( container ); + customizeContainer( container ); container.getLoggerManager().setThresholds( cliRequest.request.getLoggingLevel() ); @@ -578,7 +624,7 @@ public class MavenCli { slf4jLogger.error( "" ); slf4jLogger.error( "For more information about the errors and possible solutions" - + ", please read the following articles:" ); + + ", please read the following articles:" ); for ( Map.Entry<String, String> entry : references.entrySet() ) { @@ -610,8 +656,7 @@ public class MavenCli } } - private void logSummary( ExceptionSummary summary, Map<String, String> references, String indent, - boolean showErrors ) + private void logSummary( ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors ) { String referenceKey = ""; @@ -675,8 +720,7 @@ public class MavenCli if ( !userSettingsFile.isFile() ) { - throw new FileNotFoundException( "The specified user settings file does not exist: " - + userSettingsFile ); + throw new FileNotFoundException( "The specified user settings file does not exist: " + userSettingsFile ); } } else @@ -880,7 +924,7 @@ public class MavenCli if ( quiet ) { transferListener = new QuietMavenTransferListener(); - } + } else if ( request.isInteractiveMode() && !cliRequest.commandLine.hasOption( CLIManager.LOG_FILE ) ) { // @@ -914,20 +958,20 @@ public class MavenCli userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE; } - request.setBaseDirectory( baseDirectory ).setGoals( goals ) - .setSystemProperties( cliRequest.systemProperties ) - .setUserProperties( cliRequest.userProperties ) - .setReactorFailureBehavior( reactorFailureBehaviour ) // default: fail fast - .setRecursive( recursive ) // default: true - .setShowErrors( showErrors ) // default: false - .addActiveProfiles( activeProfiles ) // optional - .addInactiveProfiles( inactiveProfiles ) // optional - .setExecutionListener( executionListener ) - .setTransferListener( transferListener ) // default: batch mode which goes along with interactive - .setUpdateSnapshots( updateSnapshots ) // default: false - .setNoSnapshotUpdates( noSnapshotUpdates ) // default: false - .setGlobalChecksumPolicy( globalChecksumPolicy ) // default: warn - .setUserToolchainsFile( userToolchainsFile ); + request.setBaseDirectory( baseDirectory ).setGoals( goals ).setSystemProperties( cliRequest.systemProperties ).setUserProperties( cliRequest.userProperties ).setReactorFailureBehavior( reactorFailureBehaviour ) // default: + // fail + // fast + .setRecursive( recursive ) // default: true + .setShowErrors( showErrors ) // default: false + .addActiveProfiles( activeProfiles ) // optional + .addInactiveProfiles( inactiveProfiles ) // optional + .setExecutionListener( executionListener ).setTransferListener( transferListener ) // default: batch mode which + // goes along with + // interactive + .setUpdateSnapshots( updateSnapshots ) // default: false + .setNoSnapshotUpdates( noSnapshotUpdates ) // default: false + .setGlobalChecksumPolicy( globalChecksumPolicy ) // default: warn + .setUserToolchainsFile( userToolchainsFile ); if ( alternatePomFile != null ) { @@ -971,18 +1015,17 @@ public class MavenCli request.setSelectedProjects( projects ); } - if ( commandLine.hasOption( CLIManager.ALSO_MAKE ) - && !commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) ) + if ( commandLine.hasOption( CLIManager.ALSO_MAKE ) && !commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) ) { request.setMakeBehavior( MavenExecutionRequest.REACTOR_MAKE_UPSTREAM ); } else if ( !commandLine.hasOption( CLIManager.ALSO_MAKE ) - && commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) ) + && commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) ) { request.setMakeBehavior( MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM ); } else if ( commandLine.hasOption( CLIManager.ALSO_MAKE ) - && commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) ) + && commandLine.hasOption( CLIManager.ALSO_MAKE_DEPENDENTS ) ) { request.setMakeBehavior( MavenExecutionRequest.REACTOR_MAKE_BOTH ); } @@ -999,10 +1042,13 @@ public class MavenCli request.setLocalRepositoryPath( localRepoProperty ); } - final String threadConfiguration = commandLine.hasOption( CLIManager.THREADS ) - ? commandLine.getOptionValue( CLIManager.THREADS ) - : request.getSystemProperties().getProperty( - MavenCli.THREADS_DEPRECATED ); // TODO: Remove this setting. Note that the int-tests use it + final String threadConfiguration = + commandLine.hasOption( CLIManager.THREADS ) ? commandLine.getOptionValue( CLIManager.THREADS ) + : request.getSystemProperties().getProperty( MavenCli.THREADS_DEPRECATED ); // TODO: Remove + // this setting. + // Note that the + // int-tests use + // it if ( threadConfiguration != null ) { @@ -1069,7 +1115,7 @@ public class MavenCli } systemProperties.putAll( System.getProperties() ); - + // ---------------------------------------------------------------------- // Properties containing info about the currently running version of Maven // These override any corresponding properties set on the command line @@ -1118,14 +1164,23 @@ public class MavenCli static class CliRequest { String[] args; + CommandLine commandLine; + ClassWorld classWorld; + String workingDirectory; + boolean debug; + boolean quiet; + boolean showErrors = true; + Properties userProperties = new Properties(); + Properties systemProperties = new Properties(); + MavenExecutionRequest request; CliRequest( String[] args, ClassWorld classWorld ) @@ -1148,21 +1203,21 @@ public class MavenCli } } - + // // Customizations available via the CLI // - - protected TransferListener getConsoleTransferListener() + + protected TransferListener getConsoleTransferListener() { return new ConsoleMavenTransferListener( System.out ); } - + protected TransferListener getBatchTransferListener() { return new Slf4jMavenTransferListener(); } - + protected void customizeContainer( PlexusContainer container ) { } @@ -1171,5 +1226,5 @@ public class MavenCli throws ComponentLookupException { return container.lookup( ModelProcessor.class ); - } + } } http://git-wip-us.apache.org/repos/asf/maven/blob/cb69308a/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d673939..ae4127e 100644 --- a/pom.xml +++ b/pom.xml @@ -212,9 +212,9 @@ </dependency> <dependency> <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> + <artifactId>slf4j-jdk14</artifactId> <version>${slf4jVersion}</version> - <scope>runtime</scope> + <scope>compile</scope> </dependency> <!-- Wagon --> <dependency>