You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/07/20 16:55:26 UTC

[23/24] incubator-ignite git commit: # ignite-788: clean up and fixes

# ignite-788: clean up and fixes


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/0b36f4f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/0b36f4f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/0b36f4f4

Branch: refs/heads/ignite-788-last-review
Commit: 0b36f4f49ab1b09f2579c9bd0ea6771d62a22afb
Parents: 39cd7b8
Author: ashutak <as...@gridgain.com>
Authored: Mon Jul 20 17:50:49 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Mon Jul 20 17:50:49 2015 +0300

----------------------------------------------------------------------
 config/ignite-log4j2.xml                        |  1 +
 modules/core/src/test/config/log4j2-test.xml    |  1 -
 .../src/test/config/log4j2-verbose-test.xml     |  3 +-
 .../ignite/logger/log4j2/ContextTestTmp.java    | 60 --------------------
 .../ignite/logger/log4j2/Log4J2Logger.java      | 45 ++++++---------
 .../org/apache/ignite/logger/log4j2/TmpTmp.java | 37 ------------
 .../logger/log4j2/GridLog4j2SelfTest.java       | 47 +++++++++++----
 .../ignite/logger/log4j2/Log4j2TestTmp.java     | 51 -----------------
 8 files changed, 55 insertions(+), 190 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0b36f4f4/config/ignite-log4j2.xml
----------------------------------------------------------------------
diff --git a/config/ignite-log4j2.xml b/config/ignite-log4j2.xml
index b6092a9..9258258 100644
--- a/config/ignite-log4j2.xml
+++ b/config/ignite-log4j2.xml
@@ -21,6 +21,7 @@
     <Appenders>
         <Console name="CONSOLE" target="SYSTEM_OUT">
             <PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
+            <ThresholdFilter level="WARN" onMatch="DENY" onMismatch="ACCEPT"/>
         </Console>
 
         <Console name="CONSOLE_ERR" target="SYSTEM_ERR">

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0b36f4f4/modules/core/src/test/config/log4j2-test.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/log4j2-test.xml b/modules/core/src/test/config/log4j2-test.xml
index ef5c461..30599cc 100644
--- a/modules/core/src/test/config/log4j2-test.xml
+++ b/modules/core/src/test/config/log4j2-test.xml
@@ -26,7 +26,6 @@
 
         <Console name="CONSOLE_ERR" target="SYSTEM_ERR">
             <PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
-            <ThresholdFilter level="OFF" onMatch="DENY" onMismatch="ACCEPT"/>
         </Console>
 
         <Routing name="FILE">

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0b36f4f4/modules/core/src/test/config/log4j2-verbose-test.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/log4j2-verbose-test.xml b/modules/core/src/test/config/log4j2-verbose-test.xml
index 81df209..b870dc8 100644
--- a/modules/core/src/test/config/log4j2-verbose-test.xml
+++ b/modules/core/src/test/config/log4j2-verbose-test.xml
@@ -21,7 +21,6 @@
     <Appenders>
         <Console name="CONSOLE_ERR" target="SYSTEM_ERR">
             <PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
-            <ThresholdFilter level="OFF" onMatch="DENY" onMismatch="ACCEPT"/>
         </Console>
 
         <Routing name="FILE">
@@ -42,7 +41,7 @@
 
     <Loggers>
         <Root level="INFO">
-            <AppenderRef ref="CONSOLE_ERR" level="INFO"/>
+            <AppenderRef ref="CONSOLE_ERR" level="WARN"/>
             <AppenderRef ref="FILE" level="DEBUG"/>
         </Root>
     </Loggers>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0b36f4f4/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java
deleted file mode 100644
index b4c9eb2..0000000
--- a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.ignite.logger.log4j2;
-
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.logging.log4j.*;
-
-import java.net.*;
-
-/**
- * TODO: Add class description.
- */
-public class ContextTestTmp {
-    public static final String CONSOLE_APPENDER = "consoleAppender";
-    public static final String CONSOLE_CTX = "consoleContext";
-    public static final String CONSOLE_LOG = "consoleLogger";
-
-    public static void main(String[] args) throws Exception {
-        final Level maxLevel = Level.DEBUG;
-
-        final URL cfgUrl = U.resolveIgniteUrl("modules/core/src/test/config/log4j2-verbose-test.xml");
-
-        org.apache.logging.log4j.core.Logger logger = Log4J2Logger.createConsoleLogger(null, null);
-
-        logTest(logger);
-
-        logTest(LogManager.getContext().getLogger(LogManager.ROOT_LOGGER_NAME));
-
-        logTest(LogManager.getContext().getLogger("Some_another_class"));
-    }
-
-    private static void logTest(Logger logger) {
-        logger.log(Level.OFF, "*******************");
-        logger.log(Level.FATAL, "*******************");
-        logger.log(Level.ERROR, "*******************");
-        logger.log(Level.WARN, "*******************");
-        logger.log(Level.INFO, "*******************");
-        logger.log(Level.DEBUG, "*******************");
-        logger.log(Level.TRACE, "*******************");
-        logger.log(Level.ALL, "*******************");
-
-        System.out.println();
-        System.out.println();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0b36f4f4/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
index dafa034..0be13bf 100644
--- a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
+++ b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
@@ -386,62 +386,53 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
      */
     @Override public Log4J2Logger getLogger(Object ctgr) {
         if (ctgr == null)
-            return new Log4J2Logger((Logger)LogManager.getRootLogger(), (Logger)LogManager.getContext().getLogger(""));
+            return new Log4J2Logger((Logger)LogManager.getRootLogger(),
+                consoleLog == null ? null : (Logger)LogManager.getContext().getLogger(""));
 
         if (ctgr instanceof Class) {
             String name = ((Class<?>)ctgr).getName();
 
-            return new Log4J2Logger((Logger)LogManager.getLogger(name), (Logger)LogManager.getContext().getLogger(name));
+            return new Log4J2Logger((Logger)LogManager.getLogger(name),
+                consoleLog == null ? null : (Logger)LogManager.getContext().getLogger(name));
         }
 
         String name = ctgr.toString();
 
-        return new Log4J2Logger((Logger)LogManager.getLogger(name), (Logger)LogManager.getContext().getLogger(name));
+        return new Log4J2Logger((Logger)LogManager.getLogger(name),
+            consoleLog == null ? null : (Logger)LogManager.getContext().getLogger(name));
     }
 
     /** {@inheritDoc} */
     @Override public void trace(String msg) {
-        if (!impl.isTraceEnabled())
-            impl.warn("Logging at TRACE level without checking if TRACE level is enabled: " + msg);
+        if (!isTraceEnabled())
+            warning("Logging at TRACE level without checking if TRACE level is enabled: " + msg);
 
         impl.trace(msg);
 
-        if (consoleLog != null) {
-            if (!consoleLog.isTraceEnabled())
-                consoleLog.warn("Logging at TRACE level without checking if TRACE level is enabled: " + msg);
-
+        if (consoleLog != null)
             consoleLog.trace(msg);
-        }
     }
 
     /** {@inheritDoc} */
     @Override public void debug(String msg) {
-        if (!impl.isDebugEnabled())
-            impl.warn("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg);
+        if (!isDebugEnabled())
+            warning("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg);
 
         impl.debug(msg);
 
-        if (consoleLog != null) {
-            if (!consoleLog.isDebugEnabled())
-                consoleLog.warn("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg);
-
+        if (consoleLog != null)
             consoleLog.debug(msg);
-        }
     }
 
     /** {@inheritDoc} */
     @Override public void info(String msg) {
-        if (!impl.isInfoEnabled())
-            impl.warn("Logging at INFO level without checking if INFO level is enabled: " + msg);
+        if (!isInfoEnabled())
+            warning("Logging at INFO level without checking if INFO level is enabled: " + msg);
 
         impl.info(msg);
 
-        if (consoleLog != null) {
-            if (!consoleLog.isInfoEnabled())
-                consoleLog.warn("Logging at INFO level without checking if INFO level is enabled: " + msg);
-
+        if (consoleLog != null)
             consoleLog.info(msg);
-        }
     }
 
     /** {@inheritDoc} */
@@ -478,17 +469,17 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
 
     /** {@inheritDoc} */
     @Override public boolean isTraceEnabled() {
-        return impl.isTraceEnabled();
+        return impl.isTraceEnabled() || (consoleLog != null && consoleLog.isTraceEnabled());
     }
 
     /** {@inheritDoc} */
     @Override public boolean isDebugEnabled() {
-        return impl.isDebugEnabled();
+        return impl.isDebugEnabled() || (consoleLog != null && consoleLog.isDebugEnabled());
     }
 
     /** {@inheritDoc} */
     @Override public boolean isInfoEnabled() {
-        return impl.isInfoEnabled();
+        return impl.isInfoEnabled() || (consoleLog != null && consoleLog.isInfoEnabled());
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0b36f4f4/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/TmpTmp.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/TmpTmp.java b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/TmpTmp.java
deleted file mode 100644
index 65ffbdb..0000000
--- a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/TmpTmp.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.ignite.logger.log4j2;
-
-import org.apache.ignite.*;
-import org.apache.ignite.configuration.*;
-
-/**
- * TODO: Add class description.
- */
-public class TmpTmp {
-    public static void main(String[] args) throws IgniteCheckedException {
-        IgniteConfiguration cfg = new IgniteConfiguration().setGridLogger(
-//            new Log4J2Logger()
-            new Log4J2Logger("config/ignite-log4j2.xml")
-        );
-
-        try(Ignite ignite = Ignition.start(cfg)) {
-            ignite.log().info("lolol");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0b36f4f4/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2SelfTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2SelfTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2SelfTest.java
index 1a44be2..0342d8b 100644
--- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2SelfTest.java
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2SelfTest.java
@@ -27,6 +27,7 @@ import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 import org.apache.ignite.testframework.*;
 import org.apache.ignite.testframework.junits.common.*;
+import org.apache.logging.log4j.*;
 
 import java.io.*;
 import java.util.*;
@@ -115,39 +116,61 @@ public class GridLog4j2SelfTest extends TestCase {
     }
 
     /**
+     * Test can be run from IDE
+     *
      * @throws Exception If failed.
      */
-    public void testVerboseMode() throws Exception {
+    public void _testVerboseMode() throws Exception {
         final PrintStream backupSysOut = System.out;
+        final PrintStream backupSysErr = System.err;
+
         final ByteArrayOutputStream testOut = new ByteArrayOutputStream();
+        final ByteArrayOutputStream testErr = new ByteArrayOutputStream();
 
         try {
-            // Redirect the default output to a stream.
             System.setOut(new PrintStream(testOut));
+            System.setErr(new PrintStream(testErr));
 
             System.setProperty("IGNITE_QUIET", "false");
 
             try (Ignite ignite = G.start(getConfiguration("verboseLogGrid", LOG_PATH_VERBOSE_TEST))) {
-                String testInfoMsg = "******* Hello Tester! INFO message *******";
-                String testDebugMsg = "******* Hello Tester! DEBUG message *******";
+                String testMsg = "******* Hello Tester! ******* ";
 
-                ignite.log().info(testInfoMsg);
-                ignite.log().debug(testDebugMsg);
+                ignite.log().error(testMsg + Level.ERROR);
+                ignite.log().warning(testMsg + Level.WARN);
+                ignite.log().info(testMsg + Level.INFO);
+                ignite.log().debug(testMsg + Level.DEBUG);
+                ignite.log().trace(testMsg + Level.TRACE);
 
                 String consoleOut = testOut.toString();
+                String consoleErr = testErr.toString();
+
+                assertTrue(consoleOut.contains(testMsg + Level.INFO));
+                assertTrue(consoleOut.contains(testMsg + Level.DEBUG));
+                assertTrue(consoleOut.contains(testMsg + Level.TRACE));
 
-                assertTrue(consoleOut.contains(testInfoMsg));
-                assertTrue(consoleOut.contains(testDebugMsg));
+                assertTrue(consoleErr.contains(testMsg + Level.ERROR));
+                assertTrue(consoleErr.contains(testMsg + Level.WARN));
+
+                assertTrue(!consoleOut.contains(testMsg + Level.ERROR));
+                assertTrue(!consoleOut.contains(testMsg + Level.WARN));
+
+                assertTrue(!consoleErr.contains(testMsg + Level.INFO));
+                assertTrue(!consoleErr.contains(testMsg + Level.DEBUG));
+                assertTrue(!consoleErr.contains(testMsg + Level.TRACE));
             }
         }
         finally {
             System.setProperty("IGNITE_QUIET", "true");
 
-            // Restore the stdout and write the String to stdout.
             System.setOut(backupSysOut);
+            System.setErr(backupSysErr);
 
-            System.out.println("***** It was at output *****");
+            System.out.println("**************** Out Console content ***************");
             System.out.println(testOut.toString());
+
+            System.err.println("**************** Err Console content ***************");
+            System.err.println(testErr.toString());
         }
     }
 
@@ -172,7 +195,7 @@ public class GridLog4j2SelfTest extends TestCase {
         String id8;
         File logFile;
 
-        try (Ignite ignite = G.start(getConfiguration("grid" + id, LOG_PATH_TEST))) {
+        try (Ignite ignite = G.start(getConfiguration("grid" + id, LOG_PATH_MAIN))) {
             id8 = U.id8(ignite.cluster().localNode().id());
 
             String logPath = "work/log/ignite-" + id8 + ".log";
@@ -194,7 +217,7 @@ public class GridLog4j2SelfTest extends TestCase {
      * Creates grid configuration.
      *
      * @param gridName Grid name.
-     * @param logPath
+     * @param logPath Logger configuration path.
      * @return Grid configuration.
      * @throws Exception If error occurred.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0b36f4f4/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java
deleted file mode 100644
index cb1d6be..0000000
--- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.ignite.logger.log4j2;
-
-import org.apache.ignite.*;
-import org.apache.ignite.configuration.*;
-
-/**
- * TODO: Add class description.
- */
-public class Log4j2TestTmp {
-    public static void main(String[] args) throws Exception {
-//        URL url = U.resolveIgniteUrl("config/ignite-log4j2.xml");
-//
-//        System.out.println(url);
-//
-//        Configurator.initialize("test logger", url.toString());
-//
-//        LogManager.getLogger("test logger").info("******************************1");
-//
-//        ThreadContext.put("nodeId", "12345");
-//
-//        LogManager.getLogger("test logger").info("******************************2");
-
-        IgniteConfiguration cfg = new IgniteConfiguration()
-            .setGridLogger(new Log4J2Logger("config/ignite-log4j2.xml"));
-
-        try (Ignite ignite = Ignition.start(cfg.setGridName("grid1"))) {
-            ignite.log().info("****** smf 1 ********");
-            try (Ignite ignite2 = Ignition.start(cfg.setGridName("grid2"))) {
-                ignite.log().info("****** smf 2 ********");
-                ignite2.log().info("****** smf 3 ********");
-            }
-        }
-    }
-}