onami-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1509668 - in /onami/sandbox/console: ./ src/main/java/org/apache/onami/console/commands/ src/main/java/org/apache/onami/console/logging/ src/main/java/org/apache/onami/console/modules/console/ src/main/resources/META-INF/services/
Date Fri, 02 Aug 2013 12:44:09 GMT
Author: simonetripodi
Date: Fri Aug  2 12:44:08 2013
New Revision: 1509668

URL: http://svn.apache.org/r1509668
Log:
slf4j/logback replaced by log4j2 - thanks Christian Grobmeier for the support!

Added:
    onami/sandbox/console/src/main/java/org/apache/onami/console/logging/
    onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiConfigurationFactory.java
  (with props)
    onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiLoggingConfiguration.java
  (with props)
    onami/sandbox/console/src/main/java/org/apache/onami/console/logging/package-info.java
  (with props)
Modified:
    onami/sandbox/console/pom.xml
    onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Config.java
    onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java
    onami/sandbox/console/src/main/java/org/apache/onami/console/commands/History.java
    onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java
    onami/sandbox/console/src/main/java/org/apache/onami/console/modules/console/ShutdownHook.java
    onami/sandbox/console/src/main/resources/META-INF/services/com.google.inject.Module

Modified: onami/sandbox/console/pom.xml
URL: http://svn.apache.org/viewvc/onami/sandbox/console/pom.xml?rev=1509668&r1=1509667&r2=1509668&view=diff
==============================================================================
--- onami/sandbox/console/pom.xml (original)
+++ onami/sandbox/console/pom.xml Fri Aug  2 12:44:08 2013
@@ -66,6 +66,7 @@
   </distributionManagement>
 
   <properties>
+    <log4j.version>2.0-beta8</log4j.version>
     <onami.logging.version>3.4.0-incubating</onami.logging.version>
   </properties>
 
@@ -106,14 +107,14 @@
      | logging world
     -->
     <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-      <version>1.7.5</version>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <version>${log4j.version}</version>
     </dependency>
     <dependency>
-      <groupId>ch.qos.logback</groupId>
-      <artifactId>logback-classic</artifactId>
-      <version>1.0.13</version>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <version>${log4j.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.onami.logging</groupId>
@@ -122,9 +123,19 @@
     </dependency>
     <dependency>
       <groupId>org.apache.onami.logging</groupId>
-      <artifactId>org.apache.onami.logging.slf4j</artifactId>
+      <artifactId>org.apache.onami.logging.log4j2</artifactId>
       <version>${onami.logging.version}</version>
       <scope>runtime</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.logging.log4j</groupId>
+          <artifactId>log4j-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.logging.log4j</groupId>
+          <artifactId>log4j-core</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
 
     <!--

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Config.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Config.java?rev=1509668&r1=1509667&r2=1509668&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Config.java (original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Config.java Fri
Aug  2 12:44:08 2013
@@ -23,8 +23,8 @@ import io.airlift.command.Command;
 
 import java.util.Map.Entry;
 
+import org.apache.logging.log4j.Logger;
 import org.apache.onami.logging.core.InjectLogger;
-import org.slf4j.Logger;
 
 import com.google.inject.Binding;
 import com.google.inject.Inject;

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java?rev=1509668&r1=1509667&r2=1509668&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java
(original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/commands/ConsoleRunner.java
Fri Aug  2 12:44:08 2013
@@ -21,11 +21,9 @@ package org.apache.onami.console.command
 
 import static com.google.inject.Guice.createInjector;
 import static java.lang.System.err;
-import static java.lang.System.setProperty;
+import static org.apache.logging.log4j.LogManager.getLogger;
 import static org.apache.onami.configuration.OnamiVariablesExpander.expandVariables;
 import static org.apache.onami.spi.modules.GuiceServiceLoader.loadModules;
-import static org.slf4j.LoggerFactory.getILoggerFactory;
-import static org.slf4j.LoggerFactory.getLogger;
 import io.airlift.command.Cli;
 import io.airlift.command.Command;
 import io.airlift.command.Help;
@@ -40,12 +38,10 @@ import java.util.List;
 
 import jline.console.ConsoleReader;
 
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.onami.console.logging.OnamiConfigurationFactory;
 import org.apache.onami.console.modules.classloader.ClassLoaderModule;
-import org.slf4j.Logger;
-
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.core.joran.spi.JoranException;
 
 import com.google.inject.Inject;
 import com.google.inject.Injector;
@@ -59,8 +55,6 @@ public final class ConsoleRunner
 
     private static final String PROMPT = "$ ";
 
-    private final Logger logger = getLogger( getClass() );
-
     @Option( name = { "-q", "--quiet" }, description = "Long errors only." )
     private boolean quiet;
 
@@ -82,9 +76,11 @@ public final class ConsoleRunner
 
         setupLogging();
 
+        Logger logger = getLogger( getClass() );
+
         // setup the classloader
 
-        ClassLoader artifactsClassLoader = getArtifactsClassLoader();
+        ClassLoader artifactsClassLoader = getArtifactsClassLoader( logger );
 
         // setup the injector by discovering modules and commands automatically
 
@@ -93,9 +89,7 @@ public final class ConsoleRunner
 
         // retrieve components needed to run the console
 
-        injector
-        .getMembersInjector( ConsoleRunner.class )
-        .injectMembers( this );
+        injector.injectMembers( this );
 
         // run!
 
@@ -158,41 +152,30 @@ public final class ConsoleRunner
 
     private void setupLogging()
     {
+        String level;
+        String pattern;
+
         if ( quiet )
         {
-            setProperty( "log.level", "ERROR" );
-            setProperty( "log.pattern", "$ [%level] %message%n" );
+            level = "ERROR";
+            pattern = "$ [%level] %message%n";
         }
         else if ( verbose )
         {
-            setProperty( "log.level", "DEBUG" );
-            setProperty( "log.pattern", "$ %date{ISO8601} [%level] [%thread] %message%n"
);
+            level = "DEBUG";
+            pattern = "$ %date{ISO8601} [%thread] %-5level %logger{36} - %message%n";
         }
         else
         {
-            setProperty( "log.level", "INFO" );
-            setProperty( "log.pattern", "$ %message%n" );
+            level = "INFO";
+            pattern = "$ %message%n";
         }
 
-        // assume SLF4J is bound to logback in the current environment
-        final LoggerContext lc = (LoggerContext) getILoggerFactory();
-
-        try
-        {
-            JoranConfigurator configurator = new JoranConfigurator();
-            configurator.setContext( lc );
-            // the context was probably already configured by default configuration
-            // rules
-            lc.reset();
-            configurator.doConfigure( getClass().getClassLoader().getResourceAsStream( "logback-config.xml"
) );
-        }
-        catch ( JoranException je )
-        {
-            // StatusPrinter should handle this
-        }
+        // assume log4j-api is bound to log4j-core in the current environment
+        ConfigurationFactory.setConfigurationFactory( new OnamiConfigurationFactory( level,
pattern ) );
     }
 
-    private ClassLoader getArtifactsClassLoader()
+    private ClassLoader getArtifactsClassLoader( Logger logger )
     {
         if ( artifacts.isEmpty() )
         {

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/commands/History.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/commands/History.java?rev=1509668&r1=1509667&r2=1509668&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/commands/History.java (original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/commands/History.java Fri
Aug  2 12:44:08 2013
@@ -25,8 +25,8 @@ import java.util.ListIterator;
 
 import jline.console.history.History.Entry;
 
+import org.apache.logging.log4j.Logger;
 import org.apache.onami.logging.core.InjectLogger;
-import org.slf4j.Logger;
 
 import com.google.inject.Inject;
 

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java?rev=1509668&r1=1509667&r2=1509668&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java (original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/commands/Version.java Fri
Aug  2 12:44:08 2013
@@ -23,8 +23,8 @@ import io.airlift.command.Command;
 
 import java.util.Locale;
 
+import org.apache.logging.log4j.Logger;
 import org.apache.onami.logging.core.InjectLogger;
-import org.slf4j.Logger;
 
 import com.google.inject.Inject;
 import com.google.inject.name.Named;

Added: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiConfigurationFactory.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiConfigurationFactory.java?rev=1509668&view=auto
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiConfigurationFactory.java
(added)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiConfigurationFactory.java
Fri Aug  2 12:44:08 2013
@@ -0,0 +1,59 @@
+package org.apache.onami.console.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.net.URI;
+
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+
+public final class OnamiConfigurationFactory
+    extends ConfigurationFactory
+{
+
+    private final String levelName;
+
+    private final String pattern;
+
+    public OnamiConfigurationFactory( String levelName, String pattern )
+    {
+        this.levelName = levelName;
+        this.pattern = pattern;
+    }
+
+    @Override
+    protected String[] getSupportedTypes()
+    {
+        return new String[] { "*" };
+    }
+
+    @Override
+    public Configuration getConfiguration( ConfigurationSource source )
+    {
+        return new OnamiLoggingConfiguration( levelName, pattern );
+    }
+
+    @Override
+    public Configuration getConfiguration( String name, URI configLocation )
+    {
+        return getConfiguration( null );
+    }
+
+}

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiConfigurationFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiConfigurationFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiConfigurationFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiLoggingConfiguration.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiLoggingConfiguration.java?rev=1509668&view=auto
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiLoggingConfiguration.java
(added)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiLoggingConfiguration.java
Fri Aug  2 12:44:08 2013
@@ -0,0 +1,61 @@
+package org.apache.onami.console.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 static org.apache.logging.log4j.core.appender.ConsoleAppender.createAppender;
+import static org.apache.logging.log4j.core.layout.PatternLayout.createLayout;
+
+import java.io.Serializable;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.config.BaseConfiguration;
+
+public class OnamiLoggingConfiguration
+    extends BaseConfiguration
+{
+
+    private final String levelName;
+
+    private final String pattern;
+
+    public OnamiLoggingConfiguration( String levelName, String pattern )
+    {
+        this.levelName = levelName;
+        this.pattern = pattern;
+    }
+
+    @Override
+    protected void doConfigure()
+    {
+        setName( "org.apache.onami.console" );
+
+        Layout<? extends Serializable> layout = createLayout( pattern, null, null,
null, null );
+        Appender<? extends Serializable> appender = createAppender( layout, null, "SYSTEM_OUT",
"Console", "false", "true" );
+        appender.start();
+        addAppender( appender );
+        getRootLogger().addAppender( appender, null, null );
+
+        Level level = Level.valueOf( levelName );
+        getRootLogger().setLevel( level );
+    }
+
+}

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiLoggingConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiLoggingConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/OnamiLoggingConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/package-info.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/logging/package-info.java?rev=1509668&view=auto
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/logging/package-info.java
(added)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/logging/package-info.java
Fri Aug  2 12:44:08 2013
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+/**
+ *
+ */
+package org.apache.onami.console.logging;

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/console/src/main/java/org/apache/onami/console/logging/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: onami/sandbox/console/src/main/java/org/apache/onami/console/modules/console/ShutdownHook.java
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/java/org/apache/onami/console/modules/console/ShutdownHook.java?rev=1509668&r1=1509667&r2=1509668&view=diff
==============================================================================
--- onami/sandbox/console/src/main/java/org/apache/onami/console/modules/console/ShutdownHook.java
(original)
+++ onami/sandbox/console/src/main/java/org/apache/onami/console/modules/console/ShutdownHook.java
Fri Aug  2 12:44:08 2013
@@ -19,9 +19,9 @@ package org.apache.onami.console.modules
  * under the License.
  */
 
+import static org.apache.logging.log4j.LogManager.getLogger;
 import static java.lang.Runtime.getRuntime;
 import static java.lang.System.currentTimeMillis;
-import static org.slf4j.LoggerFactory.getLogger;
 
 import java.io.IOException;
 import java.util.Date;
@@ -29,7 +29,7 @@ import java.util.Formatter;
 
 import jline.console.history.FileHistory;
 
-import org.slf4j.Logger;
+import org.apache.logging.log4j.Logger;
 
 final class ShutdownHook
     extends Thread

Modified: onami/sandbox/console/src/main/resources/META-INF/services/com.google.inject.Module
URL: http://svn.apache.org/viewvc/onami/sandbox/console/src/main/resources/META-INF/services/com.google.inject.Module?rev=1509668&r1=1509667&r2=1509668&view=diff
==============================================================================
--- onami/sandbox/console/src/main/resources/META-INF/services/com.google.inject.Module (original)
+++ onami/sandbox/console/src/main/resources/META-INF/services/com.google.inject.Module Fri
Aug  2 12:44:08 2013
@@ -23,4 +23,4 @@ org.apache.onami.console.modules.console
 
 # 3rd parts modules
 
-org.apache.onami.logging.slf4j.Slf4jLoggingModule
+org.apache.onami.logging.log4j2.Log4j2LoggingModule



Mime
View raw message