Updated Branches: refs/heads/logging/slf4j-log4j2 [created] fa35ca7de
Ported equivalent changes from logback branch. - Should be the same as 7f9e280522379fc0f3ac09f4d81e8188cdb54192 only with log4j2 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/fa35ca7d Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/fa35ca7d Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/fa35ca7d Branch: refs/heads/logging/slf4j-log4j2 Commit: fa35ca7ded18c927c52354a0a0ec1c0305b55466 Parents: c8536bf Author: Stephen Connolly <stephen.alan.conno...@gmail.com> Authored: Wed Dec 12 09:31:25 2012 +0000 Committer: Stephen Connolly <stephen.alan.conno...@gmail.com> Committed: Wed Dec 12 09:31:25 2012 +0000 ---------------------------------------------------------------------- apache-maven/pom.xml | 12 ++- apache-maven/src/conf/logging/log4j2-color.xml | 36 ++++ apache-maven/src/conf/logging/log4j2.xml | 36 ++++ .../src/conf/logging/simplelogger.properties | 8 - build.xml | 2 +- maven-embedder/pom.xml | 11 ++- .../main/java/org/apache/maven/cli/MavenCli.java | 126 ++++++++------- pom.xml | 16 ++- 8 files changed, 175 insertions(+), 72 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/fa35ca7d/apache-maven/pom.xml ---------------------------------------------------------------------- diff --git a/apache-maven/pom.xml b/apache-maven/pom.xml index ce547e7..8c3b9ac 100644 --- a/apache-maven/pom.xml +++ b/apache-maven/pom.xml @@ -85,7 +85,17 @@ </dependency> <dependency> <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> + <artifactId>slf4j-ext</artifactId> + <version>1.7.2</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j.adapters</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>2.0-beta3</version> + </dependency> + <dependency> + <groupId>org.fusesource.jansi</groupId> + <artifactId>jansi</artifactId> </dependency> </dependencies> http://git-wip-us.apache.org/repos/asf/maven/blob/fa35ca7d/apache-maven/src/conf/logging/log4j2-color.xml ---------------------------------------------------------------------- diff --git a/apache-maven/src/conf/logging/log4j2-color.xml b/apache-maven/src/conf/logging/log4j2-color.xml new file mode 100644 index 0000000..ec93c35 --- /dev/null +++ b/apache-maven/src/conf/logging/log4j2-color.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + + +<configuration> + <properties> + <property name="maven.logging.root.level">INFO</property> + </properties> + <appenders> + <Console name="console" target="SYSTEM_OUT"> + <PatternLayout pattern="%highlight{[%p] %msg%n%throwable}{INFO=white}" /> + </Console> + </appenders> + <loggers> + <root level="${sys:maven.logging.root.level}"> + <appender-ref ref="console"/> + </root> + </loggers> +</configuration> http://git-wip-us.apache.org/repos/asf/maven/blob/fa35ca7d/apache-maven/src/conf/logging/log4j2.xml ---------------------------------------------------------------------- diff --git a/apache-maven/src/conf/logging/log4j2.xml b/apache-maven/src/conf/logging/log4j2.xml new file mode 100644 index 0000000..935e8a6 --- /dev/null +++ b/apache-maven/src/conf/logging/log4j2.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + + +<configuration> <!--status="debug"--> + <properties> + <property name="maven.logging.root.level">INFO</property> + </properties> + <appenders> + <Console name="console" target="SYSTEM_OUT"> + <PatternLayout pattern="[%p] %msg%n%throwable"/> + </Console> + </appenders> + <loggers> + <root level="${sys:maven.logging.root.level}"> + <appender-ref ref="console"/> + </root> + </loggers> +</configuration> http://git-wip-us.apache.org/repos/asf/maven/blob/fa35ca7d/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/fa35ca7d/build.xml ---------------------------------------------------------------------- diff --git a/build.xml b/build.xml index 4bbbec9..d76031f 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 (log4j2)"/> <property name="it.workdir.version" value="3.0.x" /> <target name="initTaskDefs"> http://git-wip-us.apache.org/repos/asf/maven/blob/fa35ca7d/maven-embedder/pom.xml ---------------------------------------------------------------------- diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 587398f..2aa799b 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,14 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-ext</artifactId> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j.adapters</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + </dependency> <!-- CLI --> <dependency> <groupId>commons-cli</groupId> http://git-wip-us.apache.org/repos/asf/maven/blob/fa35ca7d/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..f4215cf 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 @@ -116,9 +116,9 @@ public class MavenCli private LoggerManager plexusLoggerManager; private ILoggerFactory slf4jLoggerFactory; - + private Logger slf4jLogger; - + private EventSpyDispatcher eventSpyDispatcher; private ModelProcessor modelProcessor; @@ -263,7 +263,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 +293,7 @@ public class MavenCli System.out.println( CLIReportingUtils.showVersion() ); throw new ExitException( 0 ); } - } + } // // All logging is handled by SFL4J @@ -306,24 +307,24 @@ public class MavenCli if ( cliRequest.debug ) { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "debug" ); + System.setProperty( "maven.logging.root.level", "debug" ); } else if ( cliRequest.quiet ) { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_ERROR ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "error" ); + System.setProperty( "maven.logging.root.level", "error" ); } else { cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_INFO ); - System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "info" ); + System.setProperty( "maven.logging.root.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() ); + System.setProperty("log4j.configurationFile", logFile.getAbsolutePath() ); try { PrintStream ps = new PrintStream( new FileOutputStream( logFile ) ); @@ -383,29 +384,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 +575,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 +607,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 +671,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 +875,7 @@ public class MavenCli if ( quiet ) { transferListener = new QuietMavenTransferListener(); - } + } else if ( request.isInteractiveMode() && !cliRequest.commandLine.hasOption( CLIManager.LOG_FILE ) ) { // @@ -914,20 +909,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 +966,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 +993,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 +1066,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 +1115,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 +1154,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 +1177,5 @@ public class MavenCli throws ComponentLookupException { return container.lookup( ModelProcessor.class ); - } + } } http://git-wip-us.apache.org/repos/asf/maven/blob/fa35ca7d/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d673939..69e1707 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,8 @@ <jxpathVersion>1.3</jxpathVersion> <aetherVersion>1.13.1</aetherVersion> <slf4jVersion>1.7.2</slf4jVersion> + <log4j2Version>2.0-beta3</log4j2Version> + <jansiVersion>1.8</jansiVersion> <maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile> <!-- Control the name of the distribution and information output by mvn --> <distributionId>apache-maven</distributionId> @@ -212,8 +214,20 @@ </dependency> <dependency> <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> + <artifactId>slf4j-ext</artifactId> <version>${slf4jVersion}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j.adapters</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>${log4j2Version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.fusesource.jansi</groupId> + <artifactId>jansi</artifactId> + <version>${jansiVersion}</version> <scope>runtime</scope> </dependency> <!-- Wagon -->