mirror of https://github.com/apache/maven.git
extracted Slf4jConfiguration interface and corresponding implementation
to clearly separate code depending on slf4j binding still need to add automatic selection of implementation
This commit is contained in:
parent
73ffdaf863
commit
39e11cf2e5
|
@ -39,8 +39,10 @@ import org.apache.maven.InternalErrorException;
|
|||
import org.apache.maven.Maven;
|
||||
import org.apache.maven.cli.event.DefaultEventSpyContext;
|
||||
import org.apache.maven.cli.event.ExecutionEventLogger;
|
||||
import org.apache.maven.cli.logging.Slf4jConfiguration;
|
||||
import org.apache.maven.cli.logging.Slf4jLoggerManager;
|
||||
import org.apache.maven.cli.logging.Slf4jStdoutLogger;
|
||||
import org.apache.maven.cli.logging.impl.Slf4jSimpleConfiguration;
|
||||
import org.apache.maven.cli.transfer.ConsoleMavenTransferListener;
|
||||
import org.apache.maven.cli.transfer.QuietMavenTransferListener;
|
||||
import org.apache.maven.cli.transfer.Slf4jMavenTransferListener;
|
||||
|
@ -131,6 +133,8 @@ public class MavenCli
|
|||
|
||||
private DefaultSecDispatcher dispatcher;
|
||||
|
||||
private Slf4jConfiguration slf4jConfiguration = new Slf4jSimpleConfiguration();
|
||||
|
||||
public MavenCli()
|
||||
{
|
||||
this( null );
|
||||
|
@ -306,24 +310,24 @@ public class MavenCli
|
|||
if ( cliRequest.debug )
|
||||
{
|
||||
cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG );
|
||||
System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "debug" );
|
||||
slf4jConfiguration.setRootLoggerLevel( MavenExecutionRequest.LOGGING_LEVEL_DEBUG );
|
||||
}
|
||||
else if ( cliRequest.quiet )
|
||||
{
|
||||
cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_ERROR );
|
||||
System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "error" );
|
||||
slf4jConfiguration.setRootLoggerLevel( MavenExecutionRequest.LOGGING_LEVEL_ERROR );
|
||||
}
|
||||
else
|
||||
{
|
||||
cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_INFO );
|
||||
System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", "info" );
|
||||
slf4jConfiguration.setRootLoggerLevel( MavenExecutionRequest.LOGGING_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() );
|
||||
slf4jConfiguration.setLoggerFile( logFile );
|
||||
try
|
||||
{
|
||||
PrintStream ps = new PrintStream( new FileOutputStream( logFile ) );
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package org.apache.maven.cli.logging;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Abstract implementation.
|
||||
*
|
||||
* @author Hervé Boutemy
|
||||
*/
|
||||
public class AbstractSlf4jConfiguration
|
||||
implements Slf4jConfiguration
|
||||
{
|
||||
private final Logger logger = LoggerFactory.getLogger( AbstractSlf4jConfiguration.class );
|
||||
|
||||
public void setRootLoggerLevel( int level )
|
||||
{
|
||||
logger.warn( "setRootLoggerLevel: operation not supported" );
|
||||
}
|
||||
|
||||
public void setLoggerFile( File output )
|
||||
{
|
||||
logger.warn( "setLoggerFile: operation not supported" );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package org.apache.maven.cli.logging;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Interface for configuration operations on loggers, which are not available in slf4j, then require per-slf4f-binding
|
||||
* implementation.
|
||||
*
|
||||
* @author Hervé Boutemy
|
||||
*/
|
||||
public interface Slf4jConfiguration
|
||||
{
|
||||
void setRootLoggerLevel( int level );
|
||||
|
||||
void setLoggerFile( File output );
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package org.apache.maven.cli.logging.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.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.maven.cli.logging.AbstractSlf4jConfiguration;
|
||||
import org.apache.maven.cli.logging.Slf4jConfiguration;
|
||||
import org.apache.maven.execution.MavenExecutionRequest;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
|
||||
/**
|
||||
* Configuration for slf4j-simple.
|
||||
*
|
||||
* @author Hervé Boutemy
|
||||
*/
|
||||
@Component( role = Slf4jConfiguration.class )
|
||||
public class Slf4jSimpleConfiguration
|
||||
extends AbstractSlf4jConfiguration
|
||||
{
|
||||
public void setRootLoggerLevel( int level )
|
||||
{
|
||||
String value = "info";
|
||||
switch ( level )
|
||||
{
|
||||
case MavenExecutionRequest.LOGGING_LEVEL_DEBUG:
|
||||
value = "debug";
|
||||
break;
|
||||
|
||||
case MavenExecutionRequest.LOGGING_LEVEL_INFO:
|
||||
value = "info";
|
||||
break;
|
||||
|
||||
case MavenExecutionRequest.LOGGING_LEVEL_ERROR:
|
||||
value = "error";
|
||||
break;
|
||||
}
|
||||
System.setProperty( "org.slf4j.simpleLogger.defaultLogLevel", value );
|
||||
}
|
||||
|
||||
public void setLoggerFile( File output )
|
||||
{
|
||||
System.setProperty( "org.slf4j.simpleLogger.logFile", output.getAbsolutePath() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue