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:19 UTC
[16/24] incubator-ignite git commit: # ignite-788: all without quite
mode
# ignite-788: all without quite mode
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2fcafcd5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2fcafcd5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2fcafcd5
Branch: refs/heads/ignite-788-last-review
Commit: 2fcafcd5edf82ef2beee97859de049347129c0ab
Parents: 4b6dd06
Author: ashutak <as...@gridgain.com>
Authored: Fri Jul 17 16:01:55 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Jul 17 16:01:55 2015 +0300
----------------------------------------------------------------------
config/ignite-log4j2.xml | 15 +-
modules/core/src/test/config/log4j2-test.xml | 10 +-
.../ignite/logger/log4j2/ContextTestTmp.java | 26 ++-
.../ignite/logger/log4j2/Log4J2Logger.java | 216 +++++++------------
.../org/apache/ignite/logger/log4j2/TmpTmp.java | 37 ++++
.../log4j2/GridLog4j2CorrectFileNameTest.java | 90 --------
.../log4j2/GridLog4j2InitializedTest.java | 45 ----
.../log4j2/GridLog4j2InitiallizationTest.java | 106 ---------
.../log4j2/GridLog4j2NotInitializedTest.java | 46 ----
.../logger/log4j2/GridLog4j2SelfTest.java | 190 ++++++++++++++++
.../testsuites/IgniteLog4j2TestSuite.java | 5 +-
11 files changed, 332 insertions(+), 454 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/config/ignite-log4j2.xml
----------------------------------------------------------------------
diff --git a/config/ignite-log4j2.xml b/config/ignite-log4j2.xml
index 95da8c5..57f567e 100644
--- a/config/ignite-log4j2.xml
+++ b/config/ignite-log4j2.xml
@@ -21,10 +21,12 @@
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
+ <ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
</Console>
<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">
@@ -39,19 +41,6 @@
</Policies>
</RollingFile>
</Route>
-
- <!--
- <Route key="$${sys:nodeId}">
- <RollingFile name="Rolling-default" fileName="work/log/ignite-default.log"
- filePattern="work/log/ignite-default-%i-%d{yyyy-MM-dd}.log.gz">
- <PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
- <Policies>
- <TimeBasedTriggeringPolicy interval="6" modulate="true" />
- <SizeBasedTriggeringPolicy size="10 MB" />
- </Policies>
- </RollingFile>
- </Route>
- -->
</Routes>
</Routing>
</Appenders>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/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 b95709b..ef5c461 100644
--- a/modules/core/src/test/config/log4j2-test.xml
+++ b/modules/core/src/test/config/log4j2-test.xml
@@ -17,21 +17,23 @@
limitations under the License.
-->
-<Configuration status="info">
+<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
+ <ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
</Console>
<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">
- <Routes pattern="$${ctx:nodeId}">
+ <Routes pattern="$${sys:nodeId}">
<Route>
- <RollingFile name="Rolling-${ctx:nodeId}" fileName="work/log/ignite-${ctx:nodeId}.log"
- filePattern="work/log/ignite-${ctx:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
+ <RollingFile name="Rolling-${sys:nodeId}" fileName="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}.log"
+ filePattern="${sys:IGNITE_HOME}/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/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
index 88540f0..1f858da 100644
--- 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
@@ -42,7 +42,7 @@ public class ContextTestTmp {
Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
- addConsoleAppender(LogManager.getRootLogger(), Level.INFO);
+// addConsoleAppender(LogManager.getRootLogger(), Level.INFO);
//
// logTest();
@@ -54,6 +54,10 @@ public class ContextTestTmp {
System.out.println(((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).getAppenders());
+ Configuration cfg = ((LoggerContext)LogManager.getContext(false)).getConfiguration();
+ System.out.println(cfg.getAppenders().containsKey("Console"));
+// System.out.println(cfg.getA.containsKey("Console"));
+
logTest();
}
@@ -69,26 +73,32 @@ public class ContextTestTmp {
}
private static void addConsoleAppender(final Logger logger, final Level maxLevel) {
- ConsoleAppender appender = ConsoleAppender.createAppender(PatternLayout.createDefaultLayout(), null,
- "SYSTEM_OUT", CONSOLE_APPENDER, null, null);
-
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration cfg = ctx.getConfiguration();
+// for (Appender a : loggerConfig.getAppenders().values()) {
+// if (a instanceof ConsoleAppender)
+// return;
+// }
+
+ ConsoleAppender appender = ConsoleAppender.createAppender(PatternLayout.createDefaultLayout(), null,
+ "SYSTEM_OUT", CONSOLE_APPENDER, null, null);
+
appender.start();
cfg.addAppender(appender);
- LoggerConfig loggerConfig = cfg.getLoggerConfig(logger.getName());
+ LoggerConfig oldLogCfg = cfg.getLoggerConfig(logger.getName());
AppenderRef ref = AppenderRef.createAppenderRef(CONSOLE_APPENDER, maxLevel, null);
- loggerConfig.getAppenderRefs().add(ref);
+ LoggerConfig newLogCfg = LoggerConfig.createLogger("false", oldLogCfg.getLevel(),
+ oldLogCfg.getName(), "true", new AppenderRef[]{ref}, null, cfg, null);
- loggerConfig.addAppender(appender, maxLevel, null);
+ newLogCfg.addAppender(appender, maxLevel, null);
- cfg.addLogger(logger.getName(), loggerConfig);
+ cfg.addLogger(logger.getName(), oldLogCfg);
ctx.updateLoggers();
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/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 a8b7a31..8fc4e57 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.layout.*;
import org.jetbrains.annotations.*;
import java.io.*;
@@ -46,7 +45,7 @@ import static org.apache.ignite.IgniteSystemProperties.*;
* Here is a typical example of configuring log4j2 logger in Ignite configuration file:
* <pre name="code" class="xml">
* <property name="gridLogger">
- * <bean class="org.apache.ignite.grid.logger.log4j2.Log4j2Logger">
+ * <bean class="org.apache.ignite.logger.log4j2.Log4J2Logger">
* <constructor-arg type="java.lang.String" value="config/ignite-log4j2.xml"/>
* </bean>
* </property>
@@ -86,10 +85,6 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
@SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
private Logger impl;
- /** Path to configuration file. */
- // TODO delete field.
- private final String path;
-
/** Quiet flag. */
private final boolean quiet;
@@ -97,45 +92,6 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
private volatile UUID nodeId;
/**
- * Creates new logger and automatically detects if root logger already
- * has appenders configured. If it does not, the root logger will be
- * configured with default appender (analogous to calling
- * {@link #Log4J2Logger(boolean) Log4J2Logger(boolean)}
- * with parameter {@code true}, otherwise, existing appenders will be used (analogous
- * to calling {@link #Log4J2Logger(boolean) Log4J2Logger(boolean)}
- * with parameter {@code false}).
- */
- public Log4J2Logger() {
- this(!isConfigured());
- }
-
- /**
- * Creates new logger. If initialize parameter is {@code true} the Log4j
- * logger will be initialized with default console appender and {@code INFO}
- * log level.
- *
- * @param init If {@code true}, then a default console appender with
- * following pattern layout will be created: {@code %d{ABSOLUTE} %-5p [%c{1}] %m%n}.
- * If {@code false}, then no implicit initialization will take place,
- * and {@code Log4j} should be configured prior to calling this
- * constructor.
- */
- public Log4J2Logger(boolean init) {
- impl = (Logger)LogManager.getRootLogger();
-
- if (init) {
- // Implementation has already been inited, passing NULL.
- addConsoleAppenderIfNeeded(Level.INFO, null);
-
- quiet = quiet0;
- }
- else
- quiet = true;
-
- path = null;
- }
-
- /**
* Creates new logger with given implementation.
*
* @param impl Log4j implementation to use.
@@ -143,9 +99,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
public Log4J2Logger(final Logger impl) {
assert impl != null;
- path = null;
-
- addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
+ addConsoleAppenderIfNeeded(new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
return impl;
}
@@ -164,14 +118,12 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
if (path == null)
throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");
- this.path = path;
-
final URL cfgUrl = U.resolveIgniteUrl(path);
if (cfgUrl == null)
throw new IgniteCheckedException("Log4j configuration path was not found: " + path);
- addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
+ addConsoleAppenderIfNeeded(new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
if (init)
Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
@@ -194,11 +146,11 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");
if (!cfgFile.exists() || cfgFile.isDirectory())
- throw new IgniteCheckedException("Log4j configuration path was not found or is a directory: " + cfgFile);
+ throw new IgniteCheckedException("Log4j2 configuration path was not found or is a directory: " + cfgFile);
- path = cfgFile.getAbsolutePath();
+ final String path = cfgFile.getAbsolutePath();
- addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
+ addConsoleAppenderIfNeeded(new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
if (init)
Configurator.initialize(LogManager.ROOT_LOGGER_NAME, path);
@@ -220,9 +172,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
if (cfgUrl == null)
throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");
- path = null;
-
- addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
+ addConsoleAppenderIfNeeded(new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
if (init)
Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
@@ -235,19 +185,6 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
}
/**
- * Checks if Log4j2 is already configured within this VM or not.
- *
- * @return {@code True} if log4j2 was already configured, {@code false} otherwise.
- */
- // TODO review
- public static boolean isConfigured() {
- Logger log =
- (Logger)LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
-
- return !log.getAppenders().isEmpty();
- }
-
- /**
* Sets level for internal log4j implementation.
*
* @param level Log level to set.
@@ -305,31 +242,29 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
/**
* Adds console appender when needed with some default logging settings.
*
- * @param logLevel Optional log level.
- * @param implInitC Optional log implementation init closure.
+ * @param initLogClo Optional log implementation init closure.
*/
- private void addConsoleAppenderIfNeeded(@Nullable Level logLevel,
- @Nullable IgniteClosure<Boolean, Logger> implInitC) {
+ private void addConsoleAppenderIfNeeded(@Nullable IgniteClosure<Boolean, Logger> initLogClo) {
if (inited) {
- if (implInitC != null)
+ if (initLogClo != null)
// Do not init.
- impl = implInitC.apply(false);
+ impl = initLogClo.apply(false);
return;
}
synchronized (mux) {
if (inited) {
- if (implInitC != null)
+ if (initLogClo != null)
// Do not init.
- impl = implInitC.apply(false);
+ impl = initLogClo.apply(false);
return;
}
- if (implInitC != null)
+ if (initLogClo != null)
// Init logger impl.
- impl = implInitC.apply(true);
+ impl = initLogClo.apply(true);
boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
@@ -337,7 +272,6 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
Logger rootLogger = null;
ConsoleAppender errAppender = null;
- // TODO impl should be core logger.
for (Logger log = impl; log != null; ) {
if (!consoleAppenderFound) {
for (Appender appender : log.getAppenders().values()) {
@@ -369,68 +303,75 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
// User configured console appender, but log is quiet.
quiet = false;
- if (!consoleAppenderFound && !quiet && Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true"))) {
- // Console appender not found => we've looked through all categories up to root.
- assert rootLogger != null;
-
- // 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.
- if (errAppender != null) {
- rootLogger.addAppender(createConsoleAppender(Level.INFO));
-
- // TODO implement.
-// if (errAppender.getThreshold() == Level.ERROR)
-// errAppender.setThreshold(Level.WARN);
- }
- else
- // No error console appender => create console appender with no level limit.
- rootLogger.addAppender(createConsoleAppender(Level.OFF));
-
- if (logLevel != null)
- impl.setLevel(logLevel);
- }
+// if (!consoleAppenderFound && !quiet && Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true"))) {
+// // Console appender not found => we've looked through all categories up to root.
+// assert rootLogger != null;
+//
+// // 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.
+// if (errAppender != null) {
+// rootLogger.addAppender(createConsoleAppender(Level.INFO));
+//
+// // TODO implement.
+//// if (errAppender.getThreshold() == Level.ERROR)
+//// errAppender.setThreshold(Level.WARN);
+//// }
+//// else
+//// // No error console appender => create console appender with no level limit.
+//// rootLogger.addAppender(createConsoleAppender(Level.OFF));
+////
+////// if (logLevel != null)
+////// impl.setLevel(logLevel);
+// }
+// else
+// // No error console appender => create console appender with no level limit.
+// rootLogger.addAppender(createConsoleAppender(Level.OFF));
+//
+// if (logLevel != null)
+// impl.setLevel(logLevel);
+// }
quiet0 = quiet;
inited = true;
}
}
- /**
- * Creates console appender with some reasonable default logging settings.
- *
- * @param maxLevel Max logging level.
- * @return New console appender.
- */
- // TODO review.
- private Appender createConsoleAppender(Level maxLevel) {
- ConsoleAppender console = ConsoleAppender.createAppender(PatternLayout.createDefaultLayout(), null,
- "SYSTEM_OUT", "console", null, null);
-
- final LoggerContext ctx = new LoggerContext("console");
-
- final Configuration cfg = ctx.getConfiguration();
-
- console.start();
-
- cfg.addAppender(console);
-
- AppenderRef ref = AppenderRef.createAppenderRef("console", null, null);
-
- AppenderRef[] refs = new AppenderRef[] {ref};
-
- LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.ALL, LogManager.ROOT_LOGGER_NAME,
- "true", refs, null, cfg, null);
-
- loggerConfig.addAppender(console, null, null);
-
- cfg.addLogger("org.apache.logging.log4j", loggerConfig);
-
- ctx.updateLoggers();
-
- ctx.getLogger("console").error("");
-
- return console;
- }
+// /**
+// * Creates console appender with some reasonable default logging settings.
+// *
+// * @param maxLevel Max logging level.
+// * @return New console appender.
+// */
+// // TODO review.
+// private Appender createConsoleAppender(Level maxLevel) {
+// ConsoleAppender console = ConsoleAppender.createAppender(PatternLayout.createDefaultLayout(), null,
+// "SYSTEM_OUT", "console", null, null);
+//
+// final LoggerContext ctx = new LoggerContext("console");
+//
+// final Configuration cfg = ctx.getConfiguration();
+//
+// console.start();
+//
+// cfg.addAppender(console);
+//
+// AppenderRef ref = AppenderRef.createAppenderRef("console", null, null);
+//
+// AppenderRef[] refs = new AppenderRef[] {ref};
+//
+// LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.ALL, LogManager.ROOT_LOGGER_NAME,
+// "true", refs, null, cfg, null);
+//
+// loggerConfig.addAppender(console, null, null);
+//
+// cfg.addLogger("org.apache.logging.log4j", loggerConfig);
+//
+// ctx.updateLoggers();
+//
+// ctx.getLogger("console").error("");
+//
+// return console;
+// }
/** {@inheritDoc} */
@Override public void setNodeId(UUID nodeId) {
@@ -444,7 +385,6 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
((LoggerContext) LogManager.getContext(false)).reconfigure();
// Hack. To touch the logger to create all log resources (files). Then #fileName() will work properly.
- // TODO review it
impl.log(Level.OFF, "");
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/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
new file mode 100644
index 0000000..65ffbdb
--- /dev/null
+++ b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/TmpTmp.java
@@ -0,0 +1,37 @@
+/*
+ * 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/2fcafcd5/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2CorrectFileNameTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2CorrectFileNameTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2CorrectFileNameTest.java
deleted file mode 100644
index 38cadfe..0000000
--- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2CorrectFileNameTest.java
+++ /dev/null
@@ -1,90 +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.testframework.junits.common.*;
-
-import java.io.*;
-
-/**
- * Tests that several grids log to files with correct names.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4j2CorrectFileNameTest extends TestCase {
- /**
- * 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))) {
- 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.
- * @return Grid configuration.
- * @throws Exception If error occurred.
- */
- private static IgniteConfiguration getConfiguration(String gridName)
- throws Exception {
- IgniteConfiguration cfg = new IgniteConfiguration();
-
- cfg.setGridName(gridName);
-
- cfg.setGridLogger(new Log4J2Logger("config/ignite-log4j2.xml"));
- cfg.setConnectorConfiguration(null);
-
- return cfg;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitializedTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitializedTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitializedTest.java
deleted file mode 100644
index 78a53b6..0000000
--- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitializedTest.java
+++ /dev/null
@@ -1,45 +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.testframework.junits.common.*;
-
-/**
- * Log4j initialized test.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4j2InitializedTest extends TestCase {
- /** */
- public void testLogInitialize() {
- IgniteLogger log = new Log4J2Logger();
-
- assert log.isInfoEnabled();
-
- if (log.isDebugEnabled())
- 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.");
-
- assert log.getLogger(GridLog4j2InitializedTest.class.getName()) instanceof Log4J2Logger;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitiallizationTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitiallizationTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitiallizationTest.java
deleted file mode 100644
index 734ca6d..0000000
--- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2InitiallizationTest.java
+++ /dev/null
@@ -1,106 +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.internal.util.typedef.internal.*;
-import org.apache.ignite.logger.*;
-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 GridLog4j2InitiallizationTest extends TestCase {
- /** */
- public static final String LOG_PATH = "modules/core/src/test/config/log4j2-test.xml";
-
- /**
- * @throws Exception If failed.
- */
- public void testFile() throws Exception {
- File xml = GridTestUtils.resolveIgnitePath(LOG_PATH);
-
- 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 testUrl() throws Exception {
- File xml = GridTestUtils.resolveIgnitePath(LOG_PATH);
-
- 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 testPath() throws Exception {
- IgniteLogger log = new Log4J2Logger(LOG_PATH).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().setNodeId(id);
-
- assertEquals(U.id8(id), System.getProperty("nodeId"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2NotInitializedTest.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2NotInitializedTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2NotInitializedTest.java
deleted file mode 100644
index 6db58bf..0000000
--- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2NotInitializedTest.java
+++ /dev/null
@@ -1,46 +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.testframework.junits.common.*;
-
-/**
- * Log4j not initialized test.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4j2NotInitializedTest extends TestCase {
- /** */
- public void testLogInitialize() {
- IgniteLogger log = new Log4J2Logger().getLogger(GridLog4j2NotInitializedTest.class);
-
- if (log.isDebugEnabled())
- log.debug("This is 'debug' message.");
- else
- System.out.println("DEBUG level is not enabled.");
-
- if (log.isInfoEnabled())
- log.info("This is 'info' message.");
- else
- System.out.println("INFO level is not enabled.");
-
- log.warning("This is 'warning' message.");
- log.error("This is 'error' message.");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/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
new file mode 100644
index 0000000..ba3f37b
--- /dev/null
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/GridLog4j2SelfTest.java
@@ -0,0 +1,190 @@
+/*
+ * 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.testframework.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.io.*;
+import java.util.*;
+
+import static org.apache.ignite.IgniteSystemProperties.*;
+
+/**
+ * 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_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"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testVerboseMode() throws Exception {
+ System.setProperty(IGNITE_QUIET, "false");
+
+// try (Ignite ignite = G.start(getConfiguration("grid" + id))) {
+// 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());
+// }
+ }
+
+ /**
+ * 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))) {
+ 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.
+ * @return Grid configuration.
+ * @throws Exception If error occurred.
+ */
+ private static IgniteConfiguration getConfiguration(String gridName)
+ throws Exception {
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ cfg.setGridName(gridName);
+
+ cfg.setGridLogger(new Log4J2Logger(LOG_PATH_MAIN));
+ cfg.setConnectorConfiguration(null);
+
+ return cfg;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2fcafcd5/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 4cc7c1a..84b6a0c 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,10 +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(GridLog4j2InitializedTest.class));
- suite.addTest(new TestSuite(GridLog4j2NotInitializedTest.class));
- suite.addTest(new TestSuite(GridLog4j2CorrectFileNameTest.class));
- suite.addTest(new TestSuite(GridLog4j2InitiallizationTest.class));
+ suite.addTest(new TestSuite(GridLog4j2SelfTest.class));
return suite;
}