diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 5fb96dced1..49a7b57629 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -74,6 +74,11 @@ org.slf4j slf4j-api + + org.slf4j + slf4j-simple + true + ch.qos.logback logback-classic 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 6737463768..5a4710fd04 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 @@ -342,10 +342,10 @@ public class MavenCli // Ignore // } - - slf4jConfiguration.setLoggerFile( logFile ); // is it really useful? redirecting stdout/stderr isn't sufficient in all cases? } + slf4jConfiguration.activate(); + plexusLoggerManager = new Slf4jLoggerManager(); slf4jLogger = slf4jLoggerFactory.getLogger( this.getClass().getName() ); } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/BaseSlf4jConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/BaseSlf4jConfiguration.java index f82137eed8..a6961848db 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/BaseSlf4jConfiguration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/BaseSlf4jConfiguration.java @@ -19,8 +19,6 @@ package org.apache.maven.cli.logging; * under the License. */ -import java.io.File; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,8 +37,8 @@ public class BaseSlf4jConfiguration logger.warn( "setRootLoggerLevel: operation not supported" ); } - public void setLoggerFile( File output ) + public void activate() { - logger.warn( "setLoggerFile: operation not supported" ); + logger.warn( "reset(): operation not supported" ); } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java index 1ab596f44d..661c9e3eb4 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java @@ -19,8 +19,6 @@ package org.apache.maven.cli.logging; * under the License. */ -import java.io.File; - /** * Interface for configuration operations on loggers, which are not available in slf4j, then require per-slf4f-binding * implementation. @@ -38,5 +36,8 @@ public interface Slf4jConfiguration */ void setRootLoggerLevel( Level level ); - void setLoggerFile( File output ); + /** + * Activate logging implementation configuration (if necessary). + */ + void activate(); } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Log4j2Configuration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Log4j2Configuration.java index c1d1275139..9cec3ccb80 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Log4j2Configuration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Log4j2Configuration.java @@ -19,8 +19,6 @@ package org.apache.maven.cli.logging.impl; * under the License. */ -import java.io.File; - import org.apache.maven.cli.logging.BaseSlf4jConfiguration; /** @@ -53,7 +51,7 @@ public class Log4j2Configuration } @Override - public void setLoggerFile( File output ) + public void activate() { // no op } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java index 2d60b75df4..b72940a3a7 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/LogbackConfiguration.java @@ -19,8 +19,6 @@ package org.apache.maven.cli.logging.impl; * under the License. */ -import java.io.File; - import org.apache.maven.cli.logging.BaseSlf4jConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +53,7 @@ public class LogbackConfiguration } @Override - public void setLoggerFile( File output ) + public void activate() { // no op } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java index f463dd8a6f..6a7f38518e 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.java @@ -19,9 +19,9 @@ package org.apache.maven.cli.logging.impl; * under the License. */ -import java.io.File; - import org.apache.maven.cli.logging.BaseSlf4jConfiguration; +import org.slf4j.MavenSlf4jFriend; +import org.slf4j.impl.MavenSlf4jSimpleFriend; /** * Configuration for slf4j-simple. @@ -53,8 +53,10 @@ public class Slf4jSimpleConfiguration } @Override - public void setLoggerFile( File output ) + public void activate() { - //System.setProperty( "org.slf4j.simpleLogger.logFile", output.getAbsolutePath() ); + // property for root logger level or System.out redirection need to be taken into account + MavenSlf4jFriend.reset(); + MavenSlf4jSimpleFriend.init(); } } diff --git a/maven-embedder/src/main/java/org/slf4j/MavenSlf4jFriend.java b/maven-embedder/src/main/java/org/slf4j/MavenSlf4jFriend.java new file mode 100644 index 0000000000..8a43053708 --- /dev/null +++ b/maven-embedder/src/main/java/org/slf4j/MavenSlf4jFriend.java @@ -0,0 +1,35 @@ +package org.slf4j; + +/* + * 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. + */ + +/** + * Utility for Maven to access Slf4j internals through package access. + * Use with precaution, since this is not normally intended for production use. + */ +public class MavenSlf4jFriend +{ + /** + * Reset Slf4j internal state. + */ + public static void reset() + { + LoggerFactory.reset(); + } +} diff --git a/maven-embedder/src/main/java/org/slf4j/impl/MavenSlf4jSimpleFriend.java b/maven-embedder/src/main/java/org/slf4j/impl/MavenSlf4jSimpleFriend.java new file mode 100644 index 0000000000..097ad68879 --- /dev/null +++ b/maven-embedder/src/main/java/org/slf4j/impl/MavenSlf4jSimpleFriend.java @@ -0,0 +1,32 @@ +package org.slf4j.impl; + +/* + * 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. + */ + +/** + * Utility for Maven to access Slf4j-Simple internals through package access. + * Use with precaution, since this is not normally intended for production use. + */ +public class MavenSlf4jSimpleFriend +{ + public static void init() + { + SimpleLogger.init(); + } +} diff --git a/pom.xml b/pom.xml index 6b0fa21ae9..68dec80e94 100644 --- a/pom.xml +++ b/pom.xml @@ -211,12 +211,13 @@ org.slf4j slf4j-simple ${slf4jVersion} - runtime + true ch.qos.logback logback-classic 1.0.7 + true