maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason van Zyl <ja...@tesla.io>
Subject Re: [1/2] git commit: extracted Slf4jConfiguration interface and corresponding implementation to clearly separate code depending on slf4j binding
Date Sun, 16 Dec 2012 15:05:29 GMT
Sorry, I looked it up while on my phone. We definitely don't want to use anything not specific
to SLF4J. In that case you might just want to pass in the LoggerFactory and CliRequest in
and let the implementation do whatever it needs. 

On Dec 16, 2012, at 5:16 AM, Hervé BOUTEMY <herve.boutemy@free.fr> wrote:

> Level class is lg4j specific: I can't use it
> 
> I didn't find anything usable more specific than int: ideas welcome.
> 
> but what I can do is adding javadoc pointing to plexus Logger constants to 
> document accepted values
> 
> Regards,
> 
> Hervé
> 
> Le samedi 15 décembre 2012 20:48:15 Jason van Zyl a écrit :
>> I would suggest you use the Level[1] class instead of a raw int for setting
>> the level.
>> 
>> [1]: http://www.slf4j.org/apidocs/org/apache/log4j/Level.html
>> 
>> jvz
>> 
>> On 2012-12-15, at 7:57 PM, hboutemy@apache.org wrote:
>>> Updated Branches:
>>> refs/heads/master 915b1553f -> 39e11cf2e
>>> 
>>> extracted Slf4jConfiguration interface and corresponding implementation
>>> to clearly separate code depending on slf4j binding
>>> 
>>> still need to add automatic selection of implementation
>>> 
>>> Project: http://git-wip-us.apache.org/repos/asf/maven/repo
>>> Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/39e11cf2
>>> Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/39e11cf2
>>> Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/39e11cf2
>>> 
>>> Branch: refs/heads/master
>>> Commit: 39e11cf2e51a41fc47001f0fe59da251dab87587
>>> Parents: 73ffdaf
>>> Author: Hervé Boutemy <hboutemy@apache.org>
>>> Authored: Sun Dec 16 01:57:36 2012 +0100
>>> Committer: Hervé Boutemy <hboutemy@apache.org>
>>> Committed: Sun Dec 16 01:57:36 2012 +0100
>>> 
>>> ----------------------------------------------------------------------
>>> .../main/java/org/apache/maven/cli/MavenCli.java   |   12 ++-
>>> .../cli/logging/AbstractSlf4jConfiguration.java    |   46 +++++++++++
>>> .../maven/cli/logging/Slf4jConfiguration.java      |   35 ++++++++
>>> .../cli/logging/impl/Slf4jSimpleConfiguration.java |   62 +++++++++++++++
>>> 4 files changed, 151 insertions(+), 4 deletions(-)
>>> ----------------------------------------------------------------------
>>> 
>>> 
>>> http://git-wip-us.apache.org/repos/asf/maven/blob/39e11cf2/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..e3c62f8 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
>>> @@ -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 ) );
>>> 
>>> http://git-wip-us.apache.org/repos/asf/maven/blob/39e11cf2/maven-embedder/
>>> src/main/java/org/apache/maven/cli/logging/AbstractSlf4jConfiguration.java
>>> ----------------------------------------------------------------------
>>> diff --git
>>> a/maven-embedder/src/main/java/org/apache/maven/cli/logging/AbstractSlf4j
>>> Configuration.java
>>> b/maven-embedder/src/main/java/org/apache/maven/cli/logging/AbstractSlf4j
>>> Configuration.java new file mode 100644
>>> index 0000000..2b2ef6d
>>> --- /dev/null
>>> +++
>>> b/maven-embedder/src/main/java/org/apache/maven/cli/logging/AbstractSlf4j
>>> Configuration.java @@ -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" );
>>> +    }
>>> +}
>>> 
>>> http://git-wip-us.apache.org/repos/asf/maven/blob/39e11cf2/maven-embedder/
>>> src/main/java/org/apache/maven/cli/logging/Slf4jConfiguration.java
>>> ----------------------------------------------------------------------
>>> diff --git
>>> a/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfigur
>>> ation.java
>>> b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfigur
>>> ation.java new file mode 100644
>>> index 0000000..c988bd8
>>> --- /dev/null
>>> +++
>>> b/maven-embedder/src/main/java/org/apache/maven/cli/logging/Slf4jConfigur
>>> ation.java @@ -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 );
>>> +}
>>> 
>>> http://git-wip-us.apache.org/repos/asf/maven/blob/39e11cf2/maven-embedder/
>>> src/main/java/org/apache/maven/cli/logging/impl/Slf4jSimpleConfiguration.j
>>> ava ----------------------------------------------------------------------
>>> diff --git
>>> a/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSim
>>> pleConfiguration.java
>>> b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSim
>>> pleConfiguration.java new file mode 100644
>>> index 0000000..c5d60d8
>>> --- /dev/null
>>> +++
>>> b/maven-embedder/src/main/java/org/apache/maven/cli/logging/impl/Slf4jSim
>>> pleConfiguration.java @@ -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() ); +    }
>>> +}
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder & CTO, Sonatype
Founder,  Apache Maven
http://twitter.com/jvanzyl
---------------------------------------------------------

A party which is not afraid of letting culture,
business, and welfare go to ruin completely can
be omnipotent for a while.

  -- Jakob Burckhardt






Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message