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 18:29:54 UTC
[1/3] incubator-ignite git commit: # ignite-788: self-review
Repository: incubator-ignite
Updated Branches:
refs/heads/ignite-788-last-review 83e0a6893 -> cda8d8d4c
# ignite-788: self-review
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bcf30a05
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bcf30a05
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bcf30a05
Branch: refs/heads/ignite-788-last-review
Commit: bcf30a05efd8c764d96982d464c62bd354f042de
Parents: 83e0a68
Author: ashutak <as...@gridgain.com>
Authored: Mon Jul 20 18:56:02 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Mon Jul 20 18:56:02 2015 +0300
----------------------------------------------------------------------
config/ignite-log4j.xml | 6 ++--
.../apache/ignite/internal/IgniteKernal.java | 12 +++----
modules/log4j/src/main/java/Log4jTestTmp.java | 37 --------------------
.../ignite/logger/log4j2/Log4J2Logger.java | 6 ++--
4 files changed, 12 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bcf30a05/config/ignite-log4j.xml
----------------------------------------------------------------------
diff --git a/config/ignite-log4j.xml b/config/ignite-log4j.xml
index 192e945..9d4521a 100644
--- a/config/ignite-log4j.xml
+++ b/config/ignite-log4j.xml
@@ -23,14 +23,14 @@
<!--
Default log4j configuration for Ignite.
-->
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!--
Logs System.out messages to console.
Note, this appender is disabled by default.
To enable, uncomment the section below and also CONSOLE appender in the <root> element.
-->
- <!--<!–-->
+ <!--
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
@@ -45,7 +45,7 @@
<param name="levelMax" value="WARN"/>
</filter>
</appender>
- <!--–>-->
+ -->
<!--
Logs all ERROR messages to console.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bcf30a05/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 3e27940..21dbf0a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -1482,6 +1482,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
if (System.getProperty(IGNITE_NO_ASCII) == null) {
String ver = "ver. " + ACK_VER_STR;
+ // Big thanks to: http://patorjk.com/software/taag
+ // Font name "Small Slant"
if (log.isInfoEnabled()) {
log.info(NL + NL +
">>> __________ ________________ " + NL +
@@ -1496,8 +1498,6 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
);
}
- // Big thanks to: http://patorjk.com/software/taag
- // Font name "Small Slant"
if (log.isQuiet()) {
U.quiet(false,
" __________ ________________ ",
@@ -1515,7 +1515,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
String fileName = log.fileName();
if (fileName != null)
- U.quiet(false, " ^-- Logging to file '" + fileName + '\'');
+ U.quiet(false, " ^-- Logging to file '" + fileName + '\'');
U.quiet(false,
" ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or \"-v\" to ignite.{sh|bat}",
@@ -2722,8 +2722,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
@Nullable @Override public <T, S> IgniteAtomicStamped<T, S> atomicStamped(String name,
@Nullable T initVal,
@Nullable S initStamp,
- boolean create)
- {
+ boolean create) {
guard();
try {
@@ -2741,8 +2740,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
@Nullable @Override public IgniteCountDownLatch countDownLatch(String name,
int cnt,
boolean autoDel,
- boolean create)
- {
+ boolean create) {
guard();
try {
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bcf30a05/modules/log4j/src/main/java/Log4jTestTmp.java
----------------------------------------------------------------------
diff --git a/modules/log4j/src/main/java/Log4jTestTmp.java b/modules/log4j/src/main/java/Log4jTestTmp.java
deleted file mode 100644
index b855ce5..0000000
--- a/modules/log4j/src/main/java/Log4jTestTmp.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.
- */
-
-import org.apache.ignite.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.logger.log4j.*;
-
-/**
- * TODO: Add class description.
- */
-public class Log4jTestTmp {
- public static void main(String[] args) throws Exception {
- IgniteConfiguration cfg = new IgniteConfiguration()
- .setGridLogger(new Log4JLogger("config/ignite-log4j.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 ********");
- }}
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bcf30a05/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 0be13bf..1dd8eb2 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
@@ -91,8 +91,10 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
@SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
private Logger impl;
- /** Auto added at verbose mode console logger (optional). */
- private volatile Logger consoleLog;
+ /** Auto added at verbose mode console logger (nullable). */
+ @GridToStringExclude
+ @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
+ private Logger consoleLog;
/** Quiet flag. */
private final boolean quiet;
[3/3] incubator-ignite git commit: # ignite-788: self-review 3
Posted by sb...@apache.org.
# ignite-788: self-review 3
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/cda8d8d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/cda8d8d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/cda8d8d4
Branch: refs/heads/ignite-788-last-review
Commit: cda8d8d4ce52e35de445c4840de7d8818b9b1ef4
Parents: bf2f61e
Author: ashutak <as...@gridgain.com>
Authored: Mon Jul 20 19:30:16 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Mon Jul 20 19:30:16 2015 +0300
----------------------------------------------------------------------
.../logger/log4j2/GridLog4j2SelfTest.java | 238 -------------------
.../logger/log4j2/Log4j2LoggerSelfTest.java | 180 ++++++++++++++
.../log4j2/Log4j2LoggerVerboseModeSelfTest.java | 121 ++++++++++
.../testsuites/IgniteLog4j2TestSuite.java | 2 +-
4 files changed, 302 insertions(+), 239 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cda8d8d4/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
deleted file mode 100644
index b97e3e8..0000000
--- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2SelfTest.java
+++ /dev/null
@@ -1,238 +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 junit.framework.*;
-import org.apache.ignite.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.logger.*;
-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.*;
-
-/**
- * Grid Log4j2 SPI test.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4j2SelfTest extends TestCase {
- /** */
- public static final String LOG_PATH_TEST = "modules/core/src/test/config/log4j2-test.xml";
-
- /** */
- public static final String LOG_PATH_VERBOSE_TEST = "modules/core/src/test/config/log4j2-verbose-test.xml";
-
- /** */
- public static final String LOG_PATH_MAIN = "config/ignite-log4j2.xml";
-
- /**
- * @throws Exception If failed.
- */
- public void testFileConstructor() throws Exception {
- File xml = GridTestUtils.resolveIgnitePath(LOG_PATH_TEST);
-
- assert xml != null;
- assert xml.exists();
-
- IgniteLogger log = new Log4J2Logger(xml).getLogger(getClass());
-
- ((LoggerNodeIdAware) log).setNodeId(UUID.randomUUID());
-
- checkLog(log);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testUrlConstructor() throws Exception {
- File xml = GridTestUtils.resolveIgnitePath(LOG_PATH_TEST);
-
- assert xml != null;
- assert xml.exists();
-
- IgniteLogger log = new Log4J2Logger(xml.toURI().toURL()).getLogger(getClass());
-
- ((LoggerNodeIdAware) log).setNodeId(UUID.randomUUID());
-
- checkLog(log);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testPathConstructor() throws Exception {
- IgniteLogger log = new Log4J2Logger(LOG_PATH_TEST).getLogger(getClass());
-
- ((LoggerNodeIdAware) log).setNodeId(UUID.randomUUID());
-
- checkLog(log);
- }
-
- /**
- * Tests log4j logging SPI.
- */
- private void checkLog(IgniteLogger log) {
- assert !log.isDebugEnabled();
- assert log.isInfoEnabled();
-
- log.debug("This is 'debug' message.");
- log.info("This is 'info' message.");
- log.warning("This is 'warning' message.");
- log.warning("This is 'warning' message.", new Exception("It's a test warning exception"));
- log.error("This is 'error' message.");
- log.error("This is 'error' message.", new Exception("It's a test error exception"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testSystemNodeId() throws Exception {
- UUID id = UUID.randomUUID();
-
- new Log4J2Logger(LOG_PATH_TEST).setNodeId(id);
-
- assertEquals(U.id8(id), System.getProperty("nodeId"));
- }
-
- /**
- * Test can be run from IDE
- *
- * @throws Exception If failed.
- */
- 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 {
- 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 testMsg = "******* Hello Tester! ******* ";
-
- 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(testMsg + Level.ERROR));
- assertTrue(consoleOut.contains(testMsg + Level.WARN));
-
- assertTrue(consoleErr.contains(testMsg + Level.ERROR));
- assertTrue(consoleErr.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");
-
- System.setOut(backupSysOut);
- System.setErr(backupSysErr);
-
- System.out.println("**************** Out Console content ***************");
- System.out.println(testOut.toString());
-
- System.err.println("**************** Err Console content ***************");
- System.err.println(testErr.toString());
- }
- }
-
- /**
- * Tests correct behaviour in case 2 local nodes are started.
- *
- * @throws Exception If error occurs.
- */
- public void testLogFilesTwoNodes() throws Exception {
- checkOneNode(0);
- checkOneNode(1);
- }
-
- /**
- * Starts the local node and checks for presence of log file.
- * Also checks that this is really a log of a started node.
- *
- * @param id Test-local node ID.
- * @throws Exception If error occurred.
- */
- private void checkOneNode(int id) throws Exception {
- String id8;
- File logFile;
-
- 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";
-
- logFile = U.resolveIgnitePath(logPath);
- assertNotNull("Failed to resolve path: " + logPath, logFile);
- assertTrue("Log file does not exist: " + logFile, logFile.exists());
-
- assertEquals(logFile.getAbsolutePath(), ignite.log().fileName());
- }
- String logContent = U.readFileToString(logFile.getAbsolutePath(), "UTF-8");
-
- assertTrue("Log file does not contain it's node ID: " + logFile,
- logContent.contains(">>> Local node [ID="+ id8.toUpperCase()));
-
- }
-
- /**
- * Creates grid configuration.
- *
- * @param gridName Grid name.
- * @param logPath Logger configuration path.
- * @return Grid configuration.
- * @throws Exception If error occurred.
- */
- private static IgniteConfiguration getConfiguration(String gridName, String logPath)
- throws Exception {
- TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
- disco.setIpFinder(new TcpDiscoveryVmIpFinder(false) {{
- setAddresses(Collections.singleton("127.0.0.1:47500..47509"));
- }});
-
- IgniteConfiguration cfg = new IgniteConfiguration()
- .setGridName(gridName)
- .setGridLogger(new Log4J2Logger(logPath))
- .setConnectorConfiguration(null)
- .setDiscoverySpi(disco);
-
- return cfg;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cda8d8d4/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java
new file mode 100644
index 0000000..3d98f9d
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java
@@ -0,0 +1,180 @@
+/*
+ * 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 junit.framework.*;
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.logger.*;
+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 java.io.*;
+import java.util.*;
+
+/**
+ * Grid Log4j2 SPI test.
+ */
+@GridCommonTest(group = "Logger")
+public class Log4j2LoggerSelfTest extends TestCase {
+ /** */
+ public static final String LOG_PATH_TEST = "modules/core/src/test/config/log4j2-test.xml";
+
+ /** */
+ public static final String LOG_PATH_VERBOSE_TEST = "modules/core/src/test/config/log4j2-verbose-test.xml";
+
+ /** */
+ public static final String LOG_PATH_MAIN = "config/ignite-log4j2.xml";
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFileConstructor() throws Exception {
+ File xml = GridTestUtils.resolveIgnitePath(LOG_PATH_TEST);
+
+ assert xml != null;
+ assert xml.exists();
+
+ IgniteLogger log = new Log4J2Logger(xml).getLogger(getClass());
+
+ ((LoggerNodeIdAware) log).setNodeId(UUID.randomUUID());
+
+ checkLog(log);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUrlConstructor() throws Exception {
+ File xml = GridTestUtils.resolveIgnitePath(LOG_PATH_TEST);
+
+ assert xml != null;
+ assert xml.exists();
+
+ IgniteLogger log = new Log4J2Logger(xml.toURI().toURL()).getLogger(getClass());
+
+ ((LoggerNodeIdAware) log).setNodeId(UUID.randomUUID());
+
+ checkLog(log);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPathConstructor() throws Exception {
+ IgniteLogger log = new Log4J2Logger(LOG_PATH_TEST).getLogger(getClass());
+
+ ((LoggerNodeIdAware) log).setNodeId(UUID.randomUUID());
+
+ checkLog(log);
+ }
+
+ /**
+ * Tests log4j logging SPI.
+ */
+ private void checkLog(IgniteLogger log) {
+ assert !log.isDebugEnabled();
+ assert log.isInfoEnabled();
+
+ log.debug("This is 'debug' message.");
+ log.info("This is 'info' message.");
+ log.warning("This is 'warning' message.");
+ log.warning("This is 'warning' message.", new Exception("It's a test warning exception"));
+ log.error("This is 'error' message.");
+ log.error("This is 'error' message.", new Exception("It's a test error exception"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSystemNodeId() throws Exception {
+ UUID id = UUID.randomUUID();
+
+ new Log4J2Logger(LOG_PATH_TEST).setNodeId(id);
+
+ assertEquals(U.id8(id), System.getProperty("nodeId"));
+ }
+
+ /**
+ * Tests correct behaviour in case 2 local nodes are started.
+ *
+ * @throws Exception If error occurs.
+ */
+ public void testLogFilesTwoNodes() throws Exception {
+ checkOneNode(0);
+ checkOneNode(1);
+ }
+
+ /**
+ * Starts the local node and checks for presence of log file.
+ * Also checks that this is really a log of a started node.
+ *
+ * @param id Test-local node ID.
+ * @throws Exception If error occurred.
+ */
+ private void checkOneNode(int id) throws Exception {
+ String id8;
+ File logFile;
+
+ 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";
+
+ logFile = U.resolveIgnitePath(logPath);
+ assertNotNull("Failed to resolve path: " + logPath, logFile);
+ assertTrue("Log file does not exist: " + logFile, logFile.exists());
+
+ assertEquals(logFile.getAbsolutePath(), ignite.log().fileName());
+ }
+ String logContent = U.readFileToString(logFile.getAbsolutePath(), "UTF-8");
+
+ assertTrue("Log file does not contain it's node ID: " + logFile,
+ logContent.contains(">>> Local node [ID="+ id8.toUpperCase()));
+
+ }
+
+ /**
+ * Creates grid configuration.
+ *
+ * @param gridName Grid name.
+ * @param logPath Logger configuration path.
+ * @return Grid configuration.
+ * @throws Exception If error occurred.
+ */
+ private static IgniteConfiguration getConfiguration(String gridName, String logPath)
+ throws Exception {
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(new TcpDiscoveryVmIpFinder(false) {{
+ setAddresses(Collections.singleton("127.0.0.1:47500..47509"));
+ }});
+
+ IgniteConfiguration cfg = new IgniteConfiguration()
+ .setGridName(gridName)
+ .setGridLogger(new Log4J2Logger(logPath))
+ .setConnectorConfiguration(null)
+ .setDiscoverySpi(disco);
+
+ return cfg;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cda8d8d4/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerVerboseModeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerVerboseModeSelfTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerVerboseModeSelfTest.java
new file mode 100644
index 0000000..ddf307e
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerVerboseModeSelfTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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 junit.framework.*;
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+import org.apache.logging.log4j.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Grid Log4j2 SPI test.
+ */
+@GridCommonTest(group = "Logger")
+public class Log4j2LoggerVerboseModeSelfTest extends TestCase {
+ /** */
+ public static final String LOG_PATH_VERBOSE_TEST = "modules/core/src/test/config/log4j2-verbose-test.xml";
+
+ /**
+ * Test does not work after another tests. Can be run from IDE as separate test.
+ *
+ * @throws Exception If failed.
+ */
+ 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 {
+ 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 testMsg = "******* Hello Tester! ******* ";
+
+ 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(testMsg + Level.ERROR));
+ assertTrue(consoleOut.contains(testMsg + Level.WARN));
+
+ assertTrue(consoleErr.contains(testMsg + Level.ERROR));
+ assertTrue(consoleErr.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");
+
+ System.setOut(backupSysOut);
+ System.setErr(backupSysErr);
+
+ System.out.println("**************** Out Console content ***************");
+ System.out.println(testOut.toString());
+
+ System.err.println("**************** Err Console content ***************");
+ System.err.println(testErr.toString());
+ }
+ }
+
+ /**
+ * Creates grid configuration.
+ *
+ * @param gridName Grid name.
+ * @param logPath Logger configuration path.
+ * @return Grid configuration.
+ * @throws Exception If error occurred.
+ */
+ private static IgniteConfiguration getConfiguration(String gridName, String logPath)
+ throws Exception {
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(new TcpDiscoveryVmIpFinder(false) {{
+ setAddresses(Collections.singleton("127.0.0.1:47500..47509"));
+ }});
+
+ IgniteConfiguration cfg = new IgniteConfiguration()
+ .setGridName(gridName)
+ .setGridLogger(new Log4J2Logger(logPath))
+ .setConnectorConfiguration(null)
+ .setDiscoverySpi(disco);
+
+ return cfg;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cda8d8d4/modules/log4j2/src/test/java/org/apache/ignite/testsuites/IgniteLog4j2TestSuite.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/testsuites/IgniteLog4j2TestSuite.java b/modules/log4j2/src/test/java/org/apache/ignite/testsuites/IgniteLog4j2TestSuite.java
index 84b6a0c..85a98c2 100644
--- a/modules/log4j2/src/test/java/org/apache/ignite/testsuites/IgniteLog4j2TestSuite.java
+++ b/modules/log4j2/src/test/java/org/apache/ignite/testsuites/IgniteLog4j2TestSuite.java
@@ -31,7 +31,7 @@ public class IgniteLog4j2TestSuite extends TestSuite {
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite("Log4j2 Logging Test Suite");
- suite.addTest(new TestSuite(GridLog4j2SelfTest.class));
+ suite.addTest(new TestSuite(Log4j2LoggerSelfTest.class));
return suite;
}
[2/3] incubator-ignite git commit: # ignite-788: self-review 2
Posted by sb...@apache.org.
# ignite-788: self-review 2
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bf2f61e9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bf2f61e9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bf2f61e9
Branch: refs/heads/ignite-788-last-review
Commit: bf2f61e9199ea891d098205dd81d9559c49a8cb6
Parents: bcf30a0
Author: ashutak <as...@gridgain.com>
Authored: Mon Jul 20 19:21:46 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Mon Jul 20 19:21:46 2015 +0300
----------------------------------------------------------------------
assembly/release-base.xml | 5 +++++
config/ignite-log4j2.xml | 4 ++--
.../apache/ignite/logger/log4j/Log4JLogger.java | 2 +-
.../ignite/logger/log4j2/Log4J2Logger.java | 21 +++++---------------
.../logger/log4j2/GridLog4j2SelfTest.java | 10 ++++------
5 files changed, 17 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf2f61e9/assembly/release-base.xml
----------------------------------------------------------------------
diff --git a/assembly/release-base.xml b/assembly/release-base.xml
index 4137566..c95966a 100644
--- a/assembly/release-base.xml
+++ b/assembly/release-base.xml
@@ -43,6 +43,11 @@
</file>
<file>
+ <source>config/ignite-log4j2.xml</source>
+ <outputDirectory>/config</outputDirectory>
+ </file>
+
+ <file>
<source>config/java.util.logging.properties</source>
<outputDirectory>/config</outputDirectory>
</file>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf2f61e9/config/ignite-log4j2.xml
----------------------------------------------------------------------
diff --git a/config/ignite-log4j2.xml b/config/ignite-log4j2.xml
index 9258258..c9c349e 100644
--- a/config/ignite-log4j2.xml
+++ b/config/ignite-log4j2.xml
@@ -21,7 +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"/>
+ <ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
</Console>
<Console name="CONSOLE_ERR" target="SYSTEM_ERR">
@@ -74,7 +74,7 @@
<AppenderRef ref="CONSOLE" level="DEBUG"/>
-->
- <AppenderRef ref="CONSOLE_ERR" level="WARN"/>
+ <AppenderRef ref="CONSOLE_ERR" level="ERROR"/>
<AppenderRef ref="FILE" level="DEBUG"/>
</Root>
</Loggers>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf2f61e9/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java
----------------------------------------------------------------------
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java
index 7969371..e3828ab 100644
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java
+++ b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java
@@ -42,7 +42,7 @@ import static org.apache.ignite.IgniteSystemProperties.*;
* Here is a typical example of configuring log4j logger in Ignite configuration file:
* <pre name="code" class="xml">
* <property name="gridLogger">
- * <bean class="org.apache.ignite.grid.logger.log4j.Log4jLogger">
+ * <bean class="org.apache.ignite.logger.log4j.Log4JLogger">
* <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/>
* </bean>
* </property>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf2f61e9/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 1dd8eb2..6d5df74 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
@@ -29,7 +29,6 @@ import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.*;
import org.apache.logging.log4j.core.appender.routing.*;
import org.apache.logging.log4j.core.config.*;
-import org.apache.logging.log4j.core.filter.*;
import org.apache.logging.log4j.core.layout.*;
import org.jetbrains.annotations.*;
@@ -275,18 +274,13 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
boolean consoleAppenderFound = false;
Logger rootLogger = null;
- ConsoleAppender errAppender = null;
for (Logger log = impl; log != null; ) {
if (!consoleAppenderFound) {
for (Appender appender : log.getAppenders().values()) {
if (appender instanceof ConsoleAppender) {
- if ("CONSOLE_ERR".equals(appender.getName())) {
- // Treat CONSOLE_ERR appender as a system one and don't count it.
- errAppender = (ConsoleAppender)appender;
-
+ if ("CONSOLE_ERR".equals(appender.getName()))
continue;
- }
consoleAppenderFound = true;
@@ -314,7 +308,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
// User launched ignite in verbose mode and did not add console appender with INFO level
// to configuration and did not set IGNITE_CONSOLE_APPENDER to false.
- consoleLog = createConsoleLogger(errAppender != null);
+ consoleLog = createConsoleLogger();
}
quiet0 = quiet;
@@ -327,7 +321,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
*
* @return Logger with auto configured console appender.
*/
- public static Logger createConsoleLogger(boolean errConsoleAppenderWasFound) {
+ public static Logger createConsoleLogger() {
LoggerContext ctx = (LoggerContext)LogManager.getContext(true);
Configuration cfg = ctx.getConfiguration();
@@ -335,19 +329,14 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
PatternLayout layout = PatternLayout.createLayout("[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n", null, null,
Charset.defaultCharset(), false, false, null, null);
- ThresholdFilter filter = null;
-
- if (errConsoleAppenderWasFound)
- filter = ThresholdFilter.createFilter(Level.WARN, Filter.Result.DENY, Filter.Result.ACCEPT);
-
- final Appender consoleApp = ConsoleAppender.createAppender(layout, filter, null, CONSOLE_APPENDER, null, null);
+ final Appender consoleApp = ConsoleAppender.createAppender(layout, null, null, CONSOLE_APPENDER, null, null);
consoleApp.start();
AppenderRef ref = AppenderRef.createAppenderRef(CONSOLE_APPENDER, Level.TRACE, null);
AppenderRef[] refs = {ref};
- LoggerConfig logCfg = LoggerConfig.createLogger("false", Level.ALL, LogManager.ROOT_LOGGER_NAME, "",
+ LoggerConfig logCfg = LoggerConfig.createLogger("false", Level.INFO, LogManager.ROOT_LOGGER_NAME, "",
refs, null, null, null);
logCfg.addAppender(consoleApp, null, null);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf2f61e9/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 0342d8b..b97e3e8 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
@@ -148,16 +148,14 @@ public class GridLog4j2SelfTest extends TestCase {
assertTrue(consoleOut.contains(testMsg + Level.INFO));
assertTrue(consoleOut.contains(testMsg + Level.DEBUG));
assertTrue(consoleOut.contains(testMsg + Level.TRACE));
+ assertTrue(consoleOut.contains(testMsg + Level.ERROR));
+ assertTrue(consoleOut.contains(testMsg + Level.WARN));
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));
+ assertTrue(consoleErr.contains(testMsg + Level.DEBUG));
+ assertTrue(consoleErr.contains(testMsg + Level.TRACE));
}
}
finally {