entry : changedLevels.entrySet())
- entry.getKey().setLevel(entry.getValue());
+ changedLevels.forEach(Configurator::setLevel);
}
finally {
changedLevels.clear();
@@ -462,13 +469,13 @@ protected IgniteLogger log() {
* default in {@link #afterTest()}.
*/
protected final void setLoggerDebugLevel() {
- Logger logger = LogManager.getLogger("org.apache.ignite");
+ String logName = "org.apache.ignite";
- Level lvl = logger.getLevel() == null ? LogManager.getRootLogger().getLevel() : logger.getLevel();
+ LoggerConfig logCfg = LoggerContext.getContext(false).getConfiguration().getLoggerConfig(logName);
- assertNull(logger + " level: " + Level.DEBUG, changedLevels.put(logger, lvl));
+ assertNull(logCfg + " level: " + Level.DEBUG, changedLevels.put(logName, logCfg.getLevel()));
- logger.setLevel(Level.DEBUG);
+ Configurator.setLevel(logName, DEBUG);
}
/**
@@ -479,43 +486,31 @@ protected final void setLoggerDebugLevel() {
* @param cat Category.
* @param cats Additional categories.
*/
- @SuppressWarnings({"deprecation"})
protected void resetLog4j(Level log4jLevel, boolean logToFile, String cat, String... cats)
throws IgniteCheckedException {
for (String c : F.concat(false, cat, F.asList(cats)))
- Logger.getLogger(c).setLevel(log4jLevel);
+ Configurator.setLevel(c, log4jLevel);
if (logToFile) {
- Logger log4j = Logger.getRootLogger();
-
- log4j.removeAllAppenders();
+ GridTestLog4jLogger.removeAllRootLoggerAppenders();
// Console appender.
- ConsoleAppender c = new ConsoleAppender();
-
- c.setName("CONSOLE_ERR");
- c.setTarget("System.err");
- c.setThreshold(Priority.WARN);
- c.setLayout(new PatternLayout("[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"));
-
- c.activateOptions();
-
- log4j.addAppender(c);
+ addRootLoggerAppender(WARN, ConsoleAppender.newBuilder()
+ .setName(CONSOLE_ERROR)
+ .setTarget(SYSTEM_ERR)
+ .setLayout(DEFAULT_PATTERN_LAYOUT)
+ .build());
// File appender.
- RollingFileAppender file = new RollingFileAppender();
-
- file.setName("FILE");
- file.setThreshold(log4jLevel);
- file.setFile(home() + "/work/log/ignite.log");
- file.setAppend(false);
- file.setMaxFileSize("10MB");
- file.setMaxBackupIndex(10);
- file.setLayout(new PatternLayout("[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"));
-
- file.activateOptions();
-
- log4j.addAppender(file);
+ addRootLoggerAppender(log4jLevel, RollingFileAppender.newBuilder()
+ .setName(FILE)
+ .withFileName(home() + "/work/log/ignite.log")
+ .withFilePattern(home() + "/work/log/ignite.log.%i")
+ .withAppend(false)
+ .withPolicy(SizeBasedTriggeringPolicy.createPolicy("10MB"))
+ .withStrategy(DefaultRolloverStrategy.newBuilder().withMax("10").build())
+ .setLayout(DEFAULT_PATTERN_LAYOUT)
+ .build());
}
}
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridLog4jRollingFileAppender.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridLog4jRollingFileAppender.java
deleted file mode 100644
index 98841d867291a..0000000000000
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridLog4jRollingFileAppender.java
+++ /dev/null
@@ -1,116 +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.testframework.junits.logger;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.UUID;
-import org.apache.ignite.IgniteSystemProperties;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.logger.LoggerNodeIdAndApplicationAware;
-import org.apache.log4j.Layout;
-import org.apache.log4j.RollingFileAppender;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Log4J {@link org.apache.log4j.RollingFileAppender} with added support for grid node IDs.
- */
-public class GridLog4jRollingFileAppender extends RollingFileAppender implements LoggerNodeIdAndApplicationAware {
- /** Node ID. */
- private UUID nodeId;
-
- /** Basic log file name. */
- private String baseFileName;
-
- /**
- * Default constructor (does not do anything).
- */
- public GridLog4jRollingFileAppender() {
- init();
- }
-
- /**
- * Instantiate a FileAppender with given parameters.
- *
- * @param layout Layout.
- * @param filename File name.
- * @throws java.io.IOException If failed.
- */
- public GridLog4jRollingFileAppender(Layout layout, String filename) throws IOException {
- super(layout, filename);
-
- init();
- }
-
- /**
- * Instantiate a FileAppender with given parameters.
- *
- * @param layout Layout.
- * @param filename File name.
- * @param append Append flag.
- * @throws java.io.IOException If failed.
- */
- public GridLog4jRollingFileAppender(Layout layout, String filename, boolean append) throws IOException {
- super(layout, filename, append);
-
- init();
- }
-
- /**
- * Initializes appender.
- */
- private void init() {
- GridTestLog4jLogger.addAppender(this);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void setApplicationAndNode(@Nullable String application, UUID nodeId) {
- A.notNull(nodeId, "nodeId");
-
- this.nodeId = nodeId;
-
- if (fileName != null) { // fileName could be null if IGNITE_HOME is not defined.
- if (baseFileName == null)
- baseFileName = fileName;
-
- fileName = U.nodeIdLogFileName(nodeId, baseFileName);
- }
- else {
- String tmpDir = IgniteSystemProperties.getString("java.io.tmpdir");
-
- if (tmpDir != null) {
- baseFileName = new File(tmpDir, "ignite.log").getAbsolutePath();
-
- fileName = U.nodeIdLogFileName(nodeId, baseFileName);
- }
- }
- }
-
- /** {@inheritDoc} */
- @Override public synchronized UUID getNodeId() {
- return nodeId;
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void setFile(String fileName, boolean fileAppend, boolean bufIO, int bufSize)
- throws IOException {
- if (nodeId != null)
- super.setFile(fileName, fileAppend, bufIO, bufSize);
- }
-}
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java
index 6563e1c84c71f..53b39f3030eb8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java
@@ -21,7 +21,6 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Enumeration;
import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
@@ -29,33 +28,49 @@
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.typedef.C1;
import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.logger.LoggerNodeIdAndApplicationAware;
-import org.apache.log4j.Appender;
-import org.apache.log4j.Category;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.FileAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.varia.LevelRangeFilter;
-import org.apache.log4j.xml.DOMConfigurator;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.appender.FileAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
+import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
+import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
+import org.apache.logging.log4j.core.filter.LevelRangeFilter;
+import org.apache.logging.log4j.core.layout.PatternLayout;
import org.jetbrains.annotations.Nullable;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_CONSOLE_APPENDER;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET;
+import static org.apache.logging.log4j.Level.INFO;
+import static org.apache.logging.log4j.Level.OFF;
+import static org.apache.logging.log4j.Level.TRACE;
+import static org.apache.logging.log4j.core.Filter.Result.ACCEPT;
+import static org.apache.logging.log4j.core.Filter.Result.DENY;
+import static org.apache.logging.log4j.core.appender.ConsoleAppender.Target.SYSTEM_ERR;
+import static org.apache.logging.log4j.core.appender.ConsoleAppender.Target.SYSTEM_OUT;
/**
* Log4j-based implementation for logging. This logger should be used
- * by loaders that have prefer log4j-based logging.
+ * by loaders that have prefer log4j2-based logging.
*
* Here is a typical example of configuring log4j logger in Ignite configuration file:
*
* <property name="gridLogger">
- * <bean class="org.apache.ignite.logger.log4j.Log4JLogger">
+ * <bean class="org.apache.ignite.logger.log4j.Log4J2Logger">
* <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/>
* </bean>
* </property>
@@ -64,13 +79,13 @@
*
* IgniteConfiguration cfg = new IgniteConfiguration();
* ...
- * URL xml = U.resolveIgniteUrl("config/custom-log4j.xml");
- * IgniteLogger log = new Log4JLogger(xml);
+ * URL xml = U.resolveIgniteUrl("config/custom-log42j.xml");
+ * IgniteLogger log = new Log4J2Logger(xml);
* ...
* cfg.setGridLogger(log);
*
*
- * Please take a look at Apache Log4j 2.x
* for additional information.
*
* It's recommended to use Ignite logger injection instead of using/instantiating
@@ -78,6 +93,26 @@
* injection.
*/
public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAndApplicationAware {
+ /** */
+ public static final String FILE = "FILE";
+
+ /** */
+ public static final String CONSOLE = "CONSOLE";
+
+ /** */
+ public static final String CONSOLE_ERROR = "CONSOLE_ERR";
+
+ /** */
+ private static final String NODE_ID = "nodeId";
+
+ /** */
+ private static final String APP_ID = "appId";
+
+ /** */
+ public static final PatternLayout DEFAULT_PATTERN_LAYOUT = PatternLayout.newBuilder()
+ .withPattern("[%d{ISO8601}][%-5p][%t][%c{1}] %m%n")
+ .build();
+
/** Appenders. */
private static Collection fileAppenders = new GridConcurrentHashSet<>();
@@ -110,10 +145,8 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAndApplica
* 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 #GridTestLog4jLogger(boolean) Log4jLogger(boolean)}
- * with parameter {@code true}, otherwise, existing appenders will be used (analogous
- * to calling {@link #GridTestLog4jLogger(boolean) Log4jLogger(boolean)}
- * with parameter {@code false}).
+ * {@link #GridTestLog4jLogger(boolean) Log4j2Logger(boolean)}
+ * with parameter {@code true}, otherwise, existing appenders will be used.
*/
public GridTestLog4jLogger() {
this(!isConfigured());
@@ -127,15 +160,15 @@ public GridTestLog4jLogger() {
* @param init If {@code true}, then a default console appender with
* following pattern layout will be created: {@code %d{ISO8601} %-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
+ * and {@code Log4j2} should be configured prior to calling this
* constructor.
*/
public GridTestLog4jLogger(boolean init) {
- impl = Logger.getRootLogger();
+ impl = LogManager.getRootLogger();
if (init) {
// Implementation has already been inited, passing NULL.
- addConsoleAppenderIfNeeded(Level.INFO, null);
+ addConsoleAppenderIfNeeded(INFO, null);
quiet = quiet0;
}
@@ -150,7 +183,7 @@ public GridTestLog4jLogger(boolean init) {
*
* @param impl Log4j implementation to use.
*/
- protected GridTestLog4jLogger(final Logger impl) {
+ public GridTestLog4jLogger(final Logger impl) {
assert impl != null;
addConsoleAppenderIfNeeded(null, new C1() {
@@ -171,21 +204,21 @@ protected GridTestLog4jLogger(final Logger impl) {
*/
public GridTestLog4jLogger(String path) throws IgniteCheckedException {
if (path == null)
- throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");
+ throw new IgniteCheckedException("Configuration XML file for Log4j2 must be specified.");
this.cfg = path;
final URL cfgUrl = U.resolveIgniteUrl(path);
if (cfgUrl == null)
- throw new IgniteCheckedException("Log4j configuration path was not found: " + path);
+ throw new IgniteCheckedException("Log4j2 configuration path was not found: " + path);
addConsoleAppenderIfNeeded(null, new C1() {
@Override public Logger apply(Boolean init) {
if (init)
- DOMConfigurator.configure(cfgUrl);
+ Configurator.initialize(LoggerConfig.ROOT, cfgUrl.getPath());
- return Logger.getRootLogger();
+ return LogManager.getRootLogger();
}
});
@@ -203,16 +236,16 @@ public GridTestLog4jLogger(File cfgFile) throws IgniteCheckedException {
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);
cfg = cfgFile.getAbsolutePath();
addConsoleAppenderIfNeeded(null, new C1() {
@Override public Logger apply(Boolean init) {
if (init)
- DOMConfigurator.configure(cfg);
+ Configurator.initialize(LoggerConfig.ROOT, cfg);
- return Logger.getRootLogger();
+ return LogManager.getRootLogger();
}
});
@@ -234,9 +267,9 @@ public GridTestLog4jLogger(final URL cfgUrl) throws IgniteCheckedException {
addConsoleAppenderIfNeeded(null, new C1() {
@Override public Logger apply(Boolean init) {
if (init)
- DOMConfigurator.configure(cfgUrl);
+ Configurator.initialize(LoggerConfig.ROOT, cfg);
- return Logger.getRootLogger();
+ return LogManager.getRootLogger();
}
});
@@ -249,7 +282,7 @@ public GridTestLog4jLogger(final URL cfgUrl) throws IgniteCheckedException {
* @return {@code True} if log4j was already configured, {@code false} otherwise.
*/
public static boolean isConfigured() {
- return Logger.getRootLogger().getAllAppenders().hasMoreElements();
+ return !(LoggerContext.getContext(false).getConfiguration() instanceof DefaultConfiguration);
}
/**
@@ -258,14 +291,14 @@ public static boolean isConfigured() {
* @param level Log level to set.
*/
public void setLevel(Level level) {
- impl.setLevel(level);
+ Configurator.setLevel(impl.getName(), level);
}
/** {@inheritDoc} */
@Nullable @Override public String fileName() {
FileAppender fapp = F.first(fileAppenders);
- return fapp != null ? fapp.getFile() : null;
+ return fapp != null ? fapp.getFileName() : null;
}
/**
@@ -299,88 +332,98 @@ private void addConsoleAppenderIfNeeded(@Nullable Level logLevel,
boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
- boolean consoleAppenderFound = false;
- Category rootCategory = null;
- ConsoleAppender errAppender = null;
+ T2 consoleAppendersFound = isConsoleAppendersConfigured();
- for (Category l = impl; l != null; ) {
- if (!consoleAppenderFound) {
- for (Enumeration appenders = l.getAllAppenders(); appenders.hasMoreElements(); ) {
- Appender appender = (Appender)appenders.nextElement();
-
- 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;
-
- continue;
- }
+ if (consoleAppendersFound.get1() && quiet)
+ // User configured console appender, but log is quiet.
+ quiet = false;
- consoleAppenderFound = true;
+ if (!consoleAppendersFound.get1() && !quiet && Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true"))) {
+ configureConsoleAppender(consoleAppendersFound.get2() ? INFO : OFF);
- break;
- }
- }
- }
+ if (logLevel != null)
+ Configurator.setLevel(impl.getName(), logLevel);
+ }
- if (l.getParent() == null) {
- rootCategory = l;
+ quiet0 = quiet;
+ inited = true;
+ }
+ }
- break;
- }
- else
- l = l.getParent();
- }
+ /** @return Pair of flags that determines whether SYSTEM_OUT and SYSTEM_ERR appenders are configured respectively. */
+ private T2 isConsoleAppendersConfigured() {
+ Configuration cfg = LoggerContext.getContext(false).getConfiguration();
- if (consoleAppenderFound && quiet)
- // User configured console appender, but log is quiet.
- quiet = false;
+ if (cfg instanceof DefaultConfiguration)
+ return new T2<>(false, 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 rootCategory != null;
+ boolean sysOut = false;
+ boolean sysErr = false;
- // 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) {
- rootCategory.addAppender(createConsoleAppender(Level.INFO));
+ for (
+ LoggerConfig logCfg = cfg.getLoggerConfig(impl.getName());
+ logCfg != null && (!sysOut || !sysErr);
+ logCfg = logCfg.getParent()
+ ) {
+ for (Appender appender : logCfg.getAppenders().values()) {
+ if (appender instanceof ConsoleAppender) {
+ if (((ConsoleAppender)appender).getTarget() == SYSTEM_ERR)
+ sysErr = true;
- if (errAppender.getThreshold() == Level.ERROR)
- errAppender.setThreshold(Level.WARN);
+ if (((ConsoleAppender)appender).getTarget() == SYSTEM_OUT)
+ sysOut = true;
}
- else
- // No error console appender => create console appender with no level limit.
- rootCategory.addAppender(createConsoleAppender(Level.OFF));
-
- if (logLevel != null)
- impl.setLevel(logLevel);
}
-
- quiet0 = quiet;
- inited = true;
}
+
+ return new T2<>(sysOut, sysErr);
}
/**
* Creates console appender with some reasonable default logging settings.
*
- * @param maxLevel Max logging level.
- * @return New console appender.
+ * @param minLvl Minimal logging level.
+ * @return Logger with auto configured console appender.
*/
- private Appender createConsoleAppender(Level maxLevel) {
- String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
+ public Logger configureConsoleAppender(Level minLvl) {
+ // from http://logging.apache.org/log4j/2.x/manual/customconfig.html
+ LoggerContext ctx = LoggerContext.getContext(false);
- // Configure output that should go to System.out
- Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
+ Configuration cfg = ctx.getConfiguration();
- LevelRangeFilter lvlFilter = new LevelRangeFilter();
+ if (cfg instanceof DefaultConfiguration) {
+ ConfigurationBuilder cfgBuilder = ConfigurationBuilderFactory.newConfigurationBuilder();
- lvlFilter.setLevelMin(Level.TRACE);
- lvlFilter.setLevelMax(maxLevel);
+ RootLoggerComponentBuilder rootLog = cfgBuilder.newRootLogger(INFO);
- app.addFilter(lvlFilter);
+ cfg = cfgBuilder.add(rootLog).build();
- return app;
+ addConsoleAppender(cfg, minLvl);
+
+ ctx.reconfigure(cfg);
+ }
+ else {
+ addConsoleAppender(cfg, minLvl);
+
+ ctx.updateLoggers();
+ }
+
+ return ctx.getRootLogger();
+ }
+
+ /** */
+ private void addConsoleAppender(Configuration logCfg, Level minLvl) {
+ Appender consoleApp = ConsoleAppender.newBuilder()
+ .setName(CONSOLE)
+ .setTarget(SYSTEM_OUT)
+ .setLayout(DEFAULT_PATTERN_LAYOUT)
+ .setFilter(LevelRangeFilter.createFilter(minLvl, TRACE, ACCEPT, DENY))
+ .build();
+
+ consoleApp.start();
+
+ logCfg.addAppender(consoleApp);
+ logCfg.getRootLogger().addAppender(consoleApp, Level.TRACE, null);
}
/**
@@ -411,13 +454,8 @@ public static void removeAppender(FileAppender a) {
this.nodeId = nodeId;
- for (FileAppender a : fileAppenders) {
- if (a instanceof LoggerNodeIdAndApplicationAware) {
- ((LoggerNodeIdAndApplicationAware)a).setApplicationAndNode(application, nodeId);
-
- a.activateOptions();
- }
- }
+ System.setProperty(NODE_ID, U.id8(nodeId));
+ System.setProperty(APP_ID, application != null ? application : "ignite");
}
/** {@inheritDoc} */
@@ -434,7 +472,7 @@ public static Collection logFiles() {
Collection res = new ArrayList<>(fileAppenders.size());
for (FileAppender a : fileAppenders)
- res.add(a.getFile());
+ res.add(a.getFileName());
return res;
}
@@ -449,9 +487,11 @@ public static Collection logFiles() {
* @return {@link org.apache.ignite.IgniteLogger} wrapper around log4j logger.
*/
@Override public GridTestLog4jLogger getLogger(Object ctgr) {
- return new GridTestLog4jLogger(ctgr == null ? Logger.getRootLogger() :
- ctgr instanceof Class ? Logger.getLogger(((Class>)ctgr).getName()) :
- Logger.getLogger(ctgr.toString()));
+ return new GridTestLog4jLogger(ctgr == null
+ ? LogManager.getRootLogger()
+ : ctgr instanceof Class
+ ? LogManager.getLogger(((Class>)ctgr).getName())
+ : LogManager.getLogger(ctgr.toString()));
}
/** {@inheritDoc} */
@@ -528,4 +568,46 @@ public static Collection logFiles() {
@Override public String toString() {
return S.toString(GridTestLog4jLogger.class, this, "config", cfg);
}
+
+ /** */
+ public static void removeAllRootLoggerAppenders() {
+ LoggerConfig rootLogCfg = LoggerContext.getContext(false).getConfiguration().getRootLogger();
+
+ for (Appender app : rootLogCfg.getAppenders().values()) {
+ rootLogCfg.removeAppender(app.getName());
+
+ app.stop();
+ }
+
+ LoggerContext.getContext(false).updateLoggers();
+ }
+
+ /** */
+ public static void addRootLoggerAppender(Level lvl, Appender app) {
+ LoggerContext ctx = LoggerContext.getContext(false);
+
+ app.start();
+
+ ctx.getConfiguration().addAppender(app);
+ ctx.getConfiguration().getRootLogger().addAppender(app, lvl, null);
+
+ ctx.updateLoggers();
+ }
+
+ /** */
+ public static void removeRootLoggerAppender(String name) {
+ LoggerConfig rootLogCfg = LoggerContext.getContext(false).getConfiguration().getRootLogger();
+
+ Appender app = rootLogCfg.getAppenders().get(name);
+
+ if (app == null)
+ return;
+
+ app.stop();
+
+ rootLogCfg.removeAppender(name);
+
+ LoggerContext.getContext(false).updateLoggers();
+
+ }
}
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLoggerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLoggerSelfTest.java
index 9b206124c1050..8f6ee15e2478f 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLoggerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLoggerSelfTest.java
@@ -19,8 +19,10 @@
import org.apache.ignite.internal.util.lang.RunnableX;
import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -46,20 +48,20 @@ public class GridTestLog4jLoggerSelfTest {
private static final GridTestLog4jLogger LOGGER = new GridTestLog4jLogger();
/** Default root level. */
- private static final Level defaultRootLevel = Logger.getRootLogger().getLevel();
+ private static final Level defaultRootLevel = LogManager.getRootLogger().getLevel();
/** */
@BeforeClass
public static void beforeTests() {
- Logger.getRootLogger().setLevel(Level.WARN);
+ Configurator.setRootLevel(Level.WARN);
}
/** */
@AfterClass
public static void afterTests() {
- Logger.getRootLogger().setLevel(defaultRootLevel);
+ Configurator.setRootLevel(defaultRootLevel);
- assertEquals(defaultRootLevel, Logger.getRootLogger().getLevel());
+ assertEquals(defaultRootLevel, LoggerContext.getContext(false).getConfiguration().getRootLogger().getLevel());
}
/** */
diff --git a/modules/dev-utils/ignite-modules-test/build.gradle b/modules/dev-utils/ignite-modules-test/build.gradle
index 395a4d2f28544..b9e7a2f3ba831 100644
--- a/modules/dev-utils/ignite-modules-test/build.gradle
+++ b/modules/dev-utils/ignite-modules-test/build.gradle
@@ -80,7 +80,6 @@ dependencies {
}*/
compile group: 'org.apache.ignite', name: 'ignite-ml', version: ignVer
- compile group: 'org.apache.ignite', name: 'ignite-log4j', version: ignVer
compile group: 'org.apache.ignite', name: 'ignite-log4j2', version: ignVer
compile group: 'org.apache.ignite', name: 'ignite-slf4j', version: ignVer
diff --git a/modules/dev-utils/pom.xml b/modules/dev-utils/pom.xml
index 8601d381936c0..c1f37a07bb9d3 100644
--- a/modules/dev-utils/pom.xml
+++ b/modules/dev-utils/pom.xml
@@ -73,8 +73,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/direct-io/pom.xml b/modules/direct-io/pom.xml
index 14554c57f5160..bcae808e66c82 100644
--- a/modules/direct-io/pom.xml
+++ b/modules/direct-io/pom.xml
@@ -101,8 +101,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/ducktests/tests/ignitetest/tests/control_utility/consistency_test.py b/modules/ducktests/tests/ignitetest/tests/control_utility/consistency_test.py
index 0ab8db657445e..80b65b3aa950a 100644
--- a/modules/ducktests/tests/ignitetest/tests/control_utility/consistency_test.py
+++ b/modules/ducktests/tests/ignitetest/tests/control_utility/consistency_test.py
@@ -75,7 +75,7 @@ def test_logging(self, ignite_version):
cfg_file = f"{ignites.config_dir}/{cfg_filename}"
- ignites.exec_command(node, f"cp {ignites.home_dir}/config/ignite-log4j2.xml {cfg_file}")
+ ignites.exec_command(node, f"cp {ignites.home_dir}/config/ignite-log4j.xml {cfg_file}")
orig = "${sys:IGNITE_HOME}/work/log".replace('/', '\\/')
fixed = ignites.log_dir.replace('/', '\\/')
diff --git a/modules/extdata/logo/pom.xml b/modules/extdata/logo/pom.xml
index b034378d5b13c..3cddb24d8cc11 100644
--- a/modules/extdata/logo/pom.xml
+++ b/modules/extdata/logo/pom.xml
@@ -79,8 +79,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/indexing/pom.xml b/modules/indexing/pom.xml
index b5c6c1702fbb1..adf7a3858b5f7 100644
--- a/modules/indexing/pom.xml
+++ b/modules/indexing/pom.xml
@@ -112,8 +112,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/stat/StatisticsViewsTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/stat/StatisticsViewsTest.java
index c31c269611dec..b0ca914f1829c 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/stat/StatisticsViewsTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/stat/StatisticsViewsTest.java
@@ -28,8 +28,8 @@
import org.apache.ignite.internal.processors.query.stat.config.StatisticsColumnOverrides;
import org.apache.ignite.internal.processors.query.stat.config.StatisticsObjectConfiguration;
import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
import org.junit.Test;
/**
@@ -171,7 +171,7 @@ public void testLocalDataView() throws Exception {
public void testEnforceStatisticValues() throws Exception {
long size = SMALL_SIZE;
- Logger.getLogger(StatisticsProcessor.class).setLevel(Level.TRACE);
+ Configurator.setLevel(StatisticsProcessor.class.getName(), Level.TRACE);
ObjectStatisticsImpl smallStat = (ObjectStatisticsImpl)statisticsMgr(0).getLocalStatistics(SMALL_KEY);
assertNotNull(smallStat);
diff --git a/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/JclLogger.java b/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/JclLogger.java
index e9268b1ccc929..309eed38172ec 100644
--- a/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/JclLogger.java
+++ b/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/JclLogger.java
@@ -37,7 +37,7 @@
* <property name="gridLogger">
* <bean class="org.apache.ignite.logger.jcl.JclLogger">
* <constructor-arg type="org.apache.commons.logging.Log">
- * <bean class="org.apache.commons.logging.impl.Log4JLogger">
+ * <bean class="org.apache.commons.logging.impl.Log42JLogger">
* <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/>
* </bean>
* </constructor-arg>
@@ -57,7 +57,7 @@
*
* IgniteConfiguration cfg = new IgniteConfiguration();
* ...
- * IgniteLogger log = new JclLogger(new Log4JLogger("config/ignite-log4j.xml"));
+ * IgniteLogger log = new JclLogger(new Log4J2Logger("config/ignite-log4j.xml"));
* ...
* cfg.setGridLogger(log);
*
diff --git a/modules/jta/pom.xml b/modules/jta/pom.xml
index 64abac589c685..1346a1e9765e0 100644
--- a/modules/jta/pom.xml
+++ b/modules/jta/pom.xml
@@ -47,8 +47,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/kubernetes/pom.xml b/modules/kubernetes/pom.xml
index 82824840d5f4d..830c4f8f3271a 100644
--- a/modules/kubernetes/pom.xml
+++ b/modules/kubernetes/pom.xml
@@ -79,8 +79,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/log4j/README.txt b/modules/log4j/README.txt
deleted file mode 100644
index 4bd1b4b26618a..0000000000000
--- a/modules/log4j/README.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-Apache Ignite Log4J Module
---------------------------
-
-Apache Ignite Log4J module provides IgniteLogger implementation based on Apache Log4J.
-
-To enable Log4J module when starting a standalone node, move 'optional/ignite-log4j' folder to
-'libs' folder before running 'ignite.{sh|bat}' script. The content of the module folder will
-be added to classpath in this case.
-
-Importing Log4J Module In Maven Project
----------------------------------------
-
-If you are using Maven to manage dependencies of your project, you can add Log4J module
-dependency like this (replace '${ignite.version}' with actual Ignite version you are
-interested in):
-
-
- ...
-
- ...
-
- org.apache.ignite
- ignite-log4j
- ${ignite.version}
-
- ...
-
- ...
-
diff --git a/modules/log4j/licenses/apache-2.0.txt b/modules/log4j/licenses/apache-2.0.txt
deleted file mode 100644
index d645695673349..0000000000000
--- a/modules/log4j/licenses/apache-2.0.txt
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed 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.
diff --git a/modules/log4j/pom.xml b/modules/log4j/pom.xml
deleted file mode 100644
index 0379cc4f311c7..0000000000000
--- a/modules/log4j/pom.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-
-
-
-
-
-
- 4.0.0
-
-
- org.apache.ignite
- ignite-parent-internal
- ${revision}
- ../../parent-internal/pom.xml
-
-
- ignite-log4j
-
- http://ignite.apache.org
-
-
-
- ${project.groupId}
- ignite-core
-
-
-
- log4j
- log4j
-
-
-
- ${project.groupId}
- ignite-core
- test-jar
- test
-
-
-
- ${project.groupId}
- ignite-tools
- test
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
- 2.8.2
-
- false
-
-
-
-
-
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JDailyRollingFileAppender.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JDailyRollingFileAppender.java
deleted file mode 100644
index 975e486b4f96b..0000000000000
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JDailyRollingFileAppender.java
+++ /dev/null
@@ -1,77 +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.log4j;
-
-import java.io.IOException;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.lang.IgniteClosure;
-import org.apache.log4j.DailyRollingFileAppender;
-import org.apache.log4j.Layout;
-
-/**
- * Log4J {@link DailyRollingFileAppender} with added support for grid node IDs.
- */
-public class Log4JDailyRollingFileAppender extends DailyRollingFileAppender implements Log4jFileAware {
- /** Basic log file name. */
- private String baseFileName;
-
- /**
- * Default constructor (does not do anything).
- */
- public Log4JDailyRollingFileAppender() {
- init();
- }
-
- /**
- * Instantiate a FileAppender with given parameters.
- *
- * @param layout Layout.
- * @param filename File name.
- * @param datePtrn Date pattern.
- * @throws IOException If failed.
- */
- public Log4JDailyRollingFileAppender(Layout layout, String filename, String datePtrn) throws IOException {
- super(layout, filename, datePtrn);
-
- init();
- }
-
- /**
- *
- */
- private void init() {
- Log4JLogger.addAppender(this);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void updateFilePath(IgniteClosure filePathClos) {
- A.notNull(filePathClos, "filePathClos");
-
- if (baseFileName == null)
- baseFileName = fileName;
-
- fileName = filePathClos.apply(baseFileName);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void setFile(String fileName, boolean fileAppend, boolean bufIO, int bufSize)
- throws IOException {
- if (baseFileName != null)
- super.setFile(fileName, fileAppend, bufIO, bufSize);
- }
-}
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JExternallyRolledFileAppender.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JExternallyRolledFileAppender.java
deleted file mode 100644
index e07c6002e2529..0000000000000
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JExternallyRolledFileAppender.java
+++ /dev/null
@@ -1,62 +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.log4j;
-
-import java.io.IOException;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.lang.IgniteClosure;
-import org.apache.log4j.varia.ExternallyRolledFileAppender;
-
-/**
- * Log4J {@link ExternallyRolledFileAppender} with added support for grid node IDs.
- */
-public class Log4JExternallyRolledFileAppender extends ExternallyRolledFileAppender implements Log4jFileAware {
- /** Basic log file name. */
- private String baseFileName;
-
- /**
- * Default constructor (does not do anything).
- */
- public Log4JExternallyRolledFileAppender() {
- init();
- }
-
- /**
- *
- */
- private void init() {
- Log4JLogger.addAppender(this);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void updateFilePath(IgniteClosure filePathClos) {
- A.notNull(filePathClos, "filePathClos");
-
- if (baseFileName == null)
- baseFileName = fileName;
-
- fileName = filePathClos.apply(baseFileName);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void setFile(String fileName, boolean fileAppend, boolean bufIO, int bufSize)
- throws IOException {
- if (baseFileName != null)
- super.setFile(fileName, fileAppend, bufIO, bufSize);
- }
-}
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JFileAppender.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JFileAppender.java
deleted file mode 100644
index 03188cd9ac3de..0000000000000
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JFileAppender.java
+++ /dev/null
@@ -1,107 +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.log4j;
-
-import java.io.IOException;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.lang.IgniteClosure;
-import org.apache.log4j.FileAppender;
-import org.apache.log4j.Layout;
-
-/**
- * Log4J {@link FileAppender} with added support for grid node IDs.
- */
-public class Log4JFileAppender extends FileAppender implements Log4jFileAware {
- /** Basic log file name. */
- private String baseFileName;
-
- /**
- * Default constructor (does not do anything).
- */
- public Log4JFileAppender() {
- init();
- }
-
- /**
- * Instantiate a FileAppender with given parameters.
- *
- * @param layout Layout.
- * @param filename File name.
- * @throws IOException If failed.
- */
- public Log4JFileAppender(Layout layout, String filename) throws IOException {
- super(layout, filename);
-
- init();
- }
-
- /**
- * Instantiate a FileAppender with given parameters.
- *
- * @param layout Layout.
- * @param filename File name.
- * @param append Append flag.
- * @throws IOException If failed.
- */
- public Log4JFileAppender(Layout layout, String filename, boolean append) throws IOException {
- super(layout, filename, append);
-
- init();
- }
-
- /**
- * Instantiate a FileAppender with given parameters.
- *
- * @param layout Layout.
- * @param filename File name.
- * @param append Append flag.
- * @param bufIO Buffered IO flag.
- * @param bufSize Buffer size.
- * @throws IOException If failed.
- */
- public Log4JFileAppender(Layout layout, String filename, boolean append, boolean bufIO, int bufSize)
- throws IOException {
- super(layout, filename, append, bufIO, bufSize);
-
- init();
- }
-
- /**
- *
- */
- private void init() {
- Log4JLogger.addAppender(this);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void setFile(String fileName, boolean fileAppend, boolean bufIO, int bufSize)
- throws IOException {
- if (baseFileName != null)
- super.setFile(fileName, fileAppend, bufIO, bufSize);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void updateFilePath(IgniteClosure filePathClos) {
- A.notNull(filePathClos, "filePathClos");
-
- if (baseFileName == null)
- baseFileName = fileName;
-
- fileName = filePathClos.apply(baseFileName);
- }
-}
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
deleted file mode 100644
index 7d31160d01129..0000000000000
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java
+++ /dev/null
@@ -1,659 +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.log4j;
-
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.UUID;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.internal.util.GridConcurrentHashSet;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.C1;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteClosure;
-import org.apache.ignite.logger.LoggerNodeIdAndApplicationAware;
-import org.apache.log4j.Appender;
-import org.apache.log4j.Category;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.FileAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.helpers.FileWatchdog;
-import org.apache.log4j.varia.LevelRangeFilter;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.jetbrains.annotations.Nullable;
-
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_CONSOLE_APPENDER;
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET;
-
-/**
- * Log4j-based implementation for logging. This logger should be used
- * by loaders that have prefer log4j-based logging.
- *
- * Here is a typical example of configuring log4j logger in Ignite configuration file:
- *
- * <property name="gridLogger">
- * <bean class="org.apache.ignite.logger.log4j.Log4JLogger">
- * <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/>
- * </bean>
- * </property>
- *
- * and from your code:
- *
- * IgniteConfiguration cfg = new IgniteConfiguration();
- * ...
- * URL xml = U.resolveIgniteUrl("config/custom-log4j.xml");
- * IgniteLogger log = new Log4JLogger(xml);
- * ...
- * cfg.setGridLogger(log);
- *
- *
- * Please take a look at Apache Log4j 1.2
- * for additional information.
- *
- * It's recommended to use Ignite logger injection instead of using/instantiating
- * logger in your task/job code. See {@link org.apache.ignite.resources.LoggerResource} annotation about logger
- * injection.
- *
- * @deprecated Log4j 1.x had reached end of life and contains critical vulnerabilities. See
- * the announcement.
- * Please, be aware this module will be removed in the next releases.
- * Use ignite-log4j2 module instead.
- */
-@Deprecated
-public class Log4JLogger implements IgniteLogger, LoggerNodeIdAndApplicationAware, Log4jFileAware {
- /** */
- public static final String DEPRECATED_MSG = "The 'ignite-log4j' module is deprecated and will be removed in the " +
- "next releases. Use 'ignite-log4j2' module instead.";
-
- /** Appenders. */
- private static Collection fileAppenders = new GridConcurrentHashSet<>();
-
- /** */
- private static volatile boolean inited;
-
- /** */
- private static volatile boolean quiet0;
-
- /** */
- private static final Object mux = new Object();
-
- /** Logger implementation. */
- @GridToStringExclude
- @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
- private Logger impl;
-
- /** Path to configuration file. */
- @GridToStringExclude
- private final String cfg;
-
- /** Quiet flag. */
- private final boolean quiet;
-
- /** Node ID. */
- @GridToStringExclude
- private 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 #Log4JLogger(boolean) Log4JLogger(boolean)}
- * with parameter {@code true}, otherwise, existing appenders will be used (analogous
- * to calling {@link #Log4JLogger(boolean) Log4JLogger(boolean)}
- * with parameter {@code false}).
- */
- public Log4JLogger() {
- 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{ISO8601} %-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 Log4JLogger(boolean init) {
- impl = Logger.getRootLogger();
-
- if (init) {
- // Implementation has already been inited, passing NULL.
- addConsoleAppenderIfNeeded(Level.INFO, null);
-
- quiet = quiet0;
- }
- else
- quiet = true;
-
- cfg = null;
-
- warning(DEPRECATED_MSG);
- }
-
- /**
- * Creates new logger with given implementation.
- *
- * @param impl Log4j implementation to use.
- */
- public Log4JLogger(final Logger impl) {
- assert impl != null;
-
- addConsoleAppenderIfNeeded(null, new C1() {
- @Override public Logger apply(Boolean init) {
- return impl;
- }
- });
-
- quiet = quiet0;
- cfg = null;
-
- warning(DEPRECATED_MSG);
- }
-
- /**
- * Creates new logger with given implementation.
- *
- * @param impl Log4j implementation to use.
- * @param path Configuration file/url path.
- */
- private Log4JLogger(final Logger impl, final String path) {
- assert impl != null;
-
- addConsoleAppenderIfNeeded(null, new C1() {
- @Override public Logger apply(Boolean init) {
- return impl;
- }
- });
-
- quiet = quiet0;
- cfg = path;
- }
-
- /**
- * Creates new logger with given configuration {@code path}.
- * Calling this constructor is equivalent to calling {@code Log4JLogger(path, FileWatchdog.DEFAULT_DELAY}.
- *
- * @param path Path to log4j configuration XML file.
- * @throws IgniteCheckedException Thrown in case logger can't be created.
- */
- public Log4JLogger(final String path) throws IgniteCheckedException {
- this(path, FileWatchdog.DEFAULT_DELAY);
- }
-
- /**
- * Creates new logger with given configuration {@code path}.
- *
- * If {@code watchDelay} is not zero, created logger will check the configuration file for changes once every
- * {@code watchDelay} milliseconds, and update its configuration if the file was changed.
- * See {@link DOMConfigurator#configureAndWatch(String, long)} for details.
- *
- * @param path Path to log4j configuration XML file.
- * @param watchDelay delay in milliseconds used to check configuration file for changes.
- * @throws IgniteCheckedException Thrown in case logger can't be created.
- */
- public Log4JLogger(final String path, long watchDelay) throws IgniteCheckedException {
- if (path == null)
- throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");
-
- if (watchDelay < 0)
- throw new IgniteCheckedException("watchDelay can't be negative: " + watchDelay);
-
- this.cfg = path;
-
- final File cfgFile = U.resolveIgnitePath(path);
-
- if (cfgFile == null)
- throw new IgniteCheckedException("Log4j configuration path was not found: " + path);
-
- addConsoleAppenderIfNeeded(null, new C1() {
- @Override public Logger apply(Boolean init) {
- if (init) {
- if (watchDelay > 0)
- DOMConfigurator.configureAndWatch(cfgFile.getPath(), watchDelay);
- else
- DOMConfigurator.configure(cfgFile.getPath());
- }
-
- return Logger.getRootLogger();
- }
- });
-
- quiet = quiet0;
-
- warning(DEPRECATED_MSG);
- }
-
- /**
- * Creates new logger with given configuration {@code cfgFile}.
- * Calling this constructor is equivalent to calling {@code Log4JLogger(cfgFile, FileWatchdog.DEFAULT_DELAY}.
- *
- * @param cfgFile Log4j configuration XML file.
- * @throws IgniteCheckedException Thrown in case logger can't be created.
- */
- public Log4JLogger(File cfgFile) throws IgniteCheckedException {
- this(cfgFile, FileWatchdog.DEFAULT_DELAY);
- }
-
- /**
- * Creates new logger with given configuration {@code cfgFile}.
- *
- * If {@code watchDelay} is not zero, created logger will check the configuration file for changes once every
- * {@code watchDelay} milliseconds, and update its configuration if the file was changed.
- * See {@link DOMConfigurator#configureAndWatch(String, long)} for details.
- *
- * @param cfgFile Log4j configuration XML file.
- * @param watchDelay delay in milliseconds used to check configuration file for changes.
- * @throws IgniteCheckedException Thrown in case logger can't be created.
- */
- public Log4JLogger(final File cfgFile, final long watchDelay) throws IgniteCheckedException {
- if (cfgFile == null)
- 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);
-
- if (watchDelay < 0)
- throw new IgniteCheckedException("watchDelay can't be negative: " + watchDelay);
-
- cfg = cfgFile.getAbsolutePath();
-
- addConsoleAppenderIfNeeded(null, new C1() {
- @Override public Logger apply(Boolean init) {
- if (init) {
- if (watchDelay > 0)
- DOMConfigurator.configureAndWatch(cfgFile.getPath(), watchDelay);
- else
- DOMConfigurator.configure(cfgFile.getPath());
- }
-
- return Logger.getRootLogger();
- }
- });
-
- quiet = quiet0;
-
- warning(DEPRECATED_MSG);
- }
-
- /**
- * Creates new logger with given configuration {@code cfgUrl}.
- * Calling this constructor is equivalent to calling {@code Log4JLogger(cfgUrl, FileWatchdog.DEFAULT_DELAY}.
- *
- * @param cfgUrl URL for Log4j configuration XML file.
- * @throws IgniteCheckedException Thrown in case logger can't be created.
- */
- public Log4JLogger(final URL cfgUrl) throws IgniteCheckedException {
- this(cfgUrl, FileWatchdog.DEFAULT_DELAY);
- }
-
- /**
- * Creates new logger with given configuration {@code cfgUrl}.
- *
- * If {@code watchDelay} is not zero, created logger will check the configuration file for changes once every
- * {@code watchDelay} milliseconds, and update its configuration if the file was changed.
- * See {@link DOMConfigurator#configureAndWatch(String, long)} for details.
- *
- * @param cfgUrl URL for Log4j configuration XML file.
- * @param watchDelay delay in milliseconds used to check configuration file for changes.
- * @throws IgniteCheckedException Thrown in case logger can't be created.
- */
- public Log4JLogger(final URL cfgUrl, final long watchDelay) throws IgniteCheckedException {
- if (cfgUrl == null)
- throw new IgniteCheckedException("Configuration XML file for Log4j must be specified.");
-
- if (watchDelay < 0)
- throw new IgniteCheckedException("watchDelay can't be negative: " + watchDelay);
-
- cfg = cfgUrl.getPath();
-
- addConsoleAppenderIfNeeded(null, new C1() {
- @Override public Logger apply(Boolean init) {
- if (init) {
- if (watchDelay > 0)
- DOMConfigurator.configureAndWatch(cfg, watchDelay);
- else
- DOMConfigurator.configure(cfg);
- }
-
- return Logger.getRootLogger();
- }
- });
-
- quiet = quiet0;
-
- warning(DEPRECATED_MSG);
- }
-
- /**
- * Checks if Log4j is already configured within this VM or not.
- *
- * @return {@code True} if log4j was already configured, {@code false} otherwise.
- */
- public static boolean isConfigured() {
- return Logger.getRootLogger().getAllAppenders().hasMoreElements();
- }
-
- /**
- * Sets level for internal log4j implementation.
- *
- * @param level Log level to set.
- */
- public void setLevel(Level level) {
- impl.setLevel(level);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String fileName() {
- FileAppender fapp = F.first(fileAppenders);
-
- return fapp != null ? fapp.getFile() : null;
- }
-
- /**
- * Adds console appender when needed with some default logging settings.
- *
- * @param logLevel Optional log level.
- * @param implInitC Optional log implementation init closure.
- */
- private void addConsoleAppenderIfNeeded(@Nullable Level logLevel,
- @Nullable IgniteClosure implInitC) {
- if (inited) {
- if (implInitC != null)
- // Do not init.
- impl = implInitC.apply(false);
-
- return;
- }
-
- synchronized (mux) {
- if (inited) {
- if (implInitC != null)
- // Do not init.
- impl = implInitC.apply(false);
-
- return;
- }
-
- if (implInitC != null)
- // Init logger impl.
- impl = implInitC.apply(true);
-
- boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
-
- boolean consoleAppenderFound = false;
- Category rootCategory = null;
- ConsoleAppender errAppender = null;
-
- for (Category l = impl; l != null; ) {
- if (!consoleAppenderFound) {
- for (Enumeration appenders = l.getAllAppenders(); appenders.hasMoreElements(); ) {
- Appender appender = (Appender)appenders.nextElement();
-
- 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;
-
- continue;
- }
-
- consoleAppenderFound = true;
-
- break;
- }
- }
- }
-
- if (l.getParent() == null) {
- rootCategory = l;
-
- break;
- }
- else
- l = l.getParent();
- }
-
- if (consoleAppenderFound && quiet)
- // 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 rootCategory != 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) {
- rootCategory.addAppender(createConsoleAppender(Level.INFO));
-
- if (errAppender.getThreshold() == Level.ERROR)
- errAppender.setThreshold(Level.WARN);
- }
- else
- // No error console appender => create console appender with no level limit.
- rootCategory.addAppender(createConsoleAppender(Level.OFF));
-
- if (logLevel != null)
- impl.setLevel(logLevel);
- }
-
- // If still don't have appenders, disable logging.
- if (!isConfigured())
- impl.setLevel(Level.OFF);
-
- quiet0 = quiet;
- inited = true;
- }
- }
-
- /**
- * Creates console appender with some reasonable default logging settings.
- *
- * @param maxLevel Max logging level.
- * @return New console appender.
- */
- private Appender createConsoleAppender(Level maxLevel) {
- String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
-
- // Configure output that should go to System.out
- Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
-
- LevelRangeFilter lvlFilter = new LevelRangeFilter();
-
- lvlFilter.setLevelMin(Level.TRACE);
- lvlFilter.setLevelMax(maxLevel);
-
- app.addFilter(lvlFilter);
-
- return app;
- }
-
- /**
- * Adds file appender.
- *
- * @param a Appender.
- */
- public static void addAppender(FileAppender a) {
- A.notNull(a, "a");
-
- fileAppenders.add(a);
- }
-
- /**
- * Removes file appender.
- *
- * @param a Appender.
- */
- public static void removeAppender(FileAppender a) {
- A.notNull(a, "a");
-
- fileAppenders.remove(a);
- }
-
- /** {@inheritDoc} */
- @Override public void setApplicationAndNode(@Nullable String application, UUID nodeId) {
- A.notNull(nodeId, "nodeId");
-
- this.nodeId = nodeId;
-
- updateFilePath(new Log4jNodeIdFilePath(application, nodeId));
- }
-
- /** {@inheritDoc} */
- @Override public UUID getNodeId() {
- return nodeId;
- }
-
- /**
- * Gets files for all registered file appenders.
- *
- * @return List of files.
- */
- public static Collection logFiles() {
- Collection res = new ArrayList<>(fileAppenders.size());
-
- for (FileAppender a : fileAppenders)
- res.add(a.getFile());
-
- return res;
- }
-
- /**
- * Gets {@link org.apache.ignite.IgniteLogger} wrapper around log4j logger for the given
- * category. If category is {@code null}, then root logger is returned. If
- * category is an instance of {@link Class} then {@code (Class)ctgr).getName()}
- * is used as category name.
- *
- * @param ctgr {@inheritDoc}
- * @return {@link org.apache.ignite.IgniteLogger} wrapper around log4j logger.
- */
- @Override public Log4JLogger getLogger(Object ctgr) {
- return new Log4JLogger(ctgr == null ? Logger.getRootLogger() :
- ctgr instanceof Class ? Logger.getLogger(((Class>)ctgr).getName()) :
- Logger.getLogger(ctgr.toString()), cfg);
- }
-
- /** {@inheritDoc} */
- @Override public void trace(String msg) {
- if (!impl.isTraceEnabled())
- warning("Logging at TRACE level without checking if TRACE level is enabled: " + msg);
-
- impl.trace(msg);
- }
-
- /** {@inheritDoc} */
- @Override public void debug(String msg) {
- if (!impl.isDebugEnabled())
- warning("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg);
-
- impl.debug(msg);
- }
-
- /** {@inheritDoc} */
- @Override public void info(String msg) {
- if (!impl.isInfoEnabled())
- warning("Logging at INFO level without checking if INFO level is enabled: " + msg);
-
- impl.info(msg);
- }
-
- /** {@inheritDoc} */
- @Override public void warning(String msg) {
- impl.warn(msg);
- }
-
- /** {@inheritDoc} */
- @Override public void warning(String msg, @Nullable Throwable e) {
- impl.warn(msg, e);
- }
-
- /** {@inheritDoc} */
- @Override public void error(String msg) {
- impl.error(msg);
- }
-
- /** {@inheritDoc} */
- @Override public void error(String msg, @Nullable Throwable e) {
- impl.error(msg, e);
- }
-
- /** {@inheritDoc} */
- @Override public boolean isTraceEnabled() {
- return impl.isTraceEnabled();
- }
-
- /** {@inheritDoc} */
- @Override public boolean isDebugEnabled() {
- return impl.isDebugEnabled();
- }
-
- /** {@inheritDoc} */
- @Override public boolean isInfoEnabled() {
- return impl.isInfoEnabled();
- }
-
- /** {@inheritDoc} */
- @Override public boolean isQuiet() {
- return quiet;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(Log4JLogger.class, this, "config", this.cfg);
- }
-
- /** {@inheritDoc} */
- @Override public void updateFilePath(IgniteClosure filePathClos) {
- A.notNull(filePathClos, "filePathClos");
-
- for (FileAppender a : fileAppenders) {
- if (a instanceof Log4jFileAware) {
- ((Log4jFileAware)a).updateFilePath(filePathClos);
-
- a.activateOptions();
- }
- }
- }
-
- /**
- * Cleans up the logger configuration. Should be used in unit tests only for sequential tests run with
- * different configurations
- */
- static void cleanup() {
- synchronized (mux) {
- if (inited)
- LogManager.shutdown();
-
- inited = false;
- }
- }
-}
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jFileAware.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jFileAware.java
deleted file mode 100644
index b2ba9b6025b3e..0000000000000
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jFileAware.java
+++ /dev/null
@@ -1,32 +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.log4j;
-
-import org.apache.ignite.lang.IgniteClosure;
-
-/**
- * Interface for those loggers and appenders that evaluate their file paths lazily.
- */
-interface Log4jFileAware {
- /**
- * Sets closure that later evaluate file path.
- *
- * @param filePathClos Closure that generates actual file path.
- */
- void updateFilePath(IgniteClosure filePathClos);
-}
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jNodeIdFilePath.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jNodeIdFilePath.java
deleted file mode 100644
index 715684dd3455e..0000000000000
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jNodeIdFilePath.java
+++ /dev/null
@@ -1,71 +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.log4j;
-
-import java.io.File;
-import java.util.UUID;
-import org.apache.ignite.IgniteSystemProperties;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteClosure;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Closure that generates file path adding node id to filename as a suffix.
- */
-class Log4jNodeIdFilePath implements IgniteClosure {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** Applictaion name. */
- private final @Nullable String app;
-
- /** Node id. */
- private final UUID nodeId;
-
- /**
- * Creates new instance.
- *
- * @param app Application name.
- * @param id Node id.
- */
- Log4jNodeIdFilePath(@Nullable String app, UUID id) {
- this.app = app;
- nodeId = id;
- }
-
- /** {@inheritDoc} */
- @Override public String apply(String oldPath) {
- String fileName = (app != null ? app : "ignite") + ".log";
-
- if (!F.isEmpty(U.IGNITE_LOG_DIR))
- return U.nodeIdLogFileName(nodeId, new File(U.IGNITE_LOG_DIR, fileName).getAbsolutePath());
-
- if (oldPath != null) // fileName could be null if IGNITE_HOME is not defined.
- return U.nodeIdLogFileName(nodeId, oldPath);
-
- String tmpDir = IgniteSystemProperties.getString("java.io.tmpdir");
-
- if (tmpDir != null)
- return U.nodeIdLogFileName(nodeId, new File(tmpDir, fileName).getAbsolutePath());
-
- System.err.println("Failed to get tmp directory for log file.");
-
- return null;
- }
-}
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jRollingFileAppender.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jRollingFileAppender.java
deleted file mode 100644
index 8181f3e72e91b..0000000000000
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jRollingFileAppender.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.log4j;
-
-import java.io.IOException;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.lang.IgniteClosure;
-import org.apache.log4j.Layout;
-import org.apache.log4j.RollingFileAppender;
-
-/**
- * Log4J {@link RollingFileAppender} with added support for grid node IDs.
- */
-public class Log4jRollingFileAppender extends RollingFileAppender implements Log4jFileAware {
- /** Basic log file name. */
- private String baseFileName;
-
- /**
- * Default constructor (does not do anything).
- */
- public Log4jRollingFileAppender() {
- init();
- }
-
- /**
- * Instantiate a FileAppender with given parameters.
- *
- * @param layout Layout.
- * @param filename File name.
- * @throws IOException If failed.
- */
- public Log4jRollingFileAppender(Layout layout, String filename) throws IOException {
- super(layout, filename);
-
- init();
- }
-
- /**
- * Instantiate a FileAppender with given parameters.
- *
- * @param layout Layout.
- * @param filename File name.
- * @param append Append flag.
- * @throws IOException If failed.
- */
- public Log4jRollingFileAppender(Layout layout, String filename, boolean append) throws IOException {
- super(layout, filename, append);
-
- init();
- }
-
- /**
- * Initializes appender.
- */
- private void init() {
- Log4JLogger.addAppender(this);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void updateFilePath(IgniteClosure filePathClos) {
- A.notNull(filePathClos, "filePathClos");
-
- if (baseFileName == null)
- baseFileName = fileName;
-
- fileName = filePathClos.apply(baseFileName);
- }
-
- /** {@inheritDoc} */
- @Override public synchronized void setFile(String fileName, boolean fileAppend, boolean bufIO, int bufSize)
- throws IOException {
- if (baseFileName != null)
- super.setFile(fileName, fileAppend, bufIO, bufSize);
- }
-}
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/package-info.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/package-info.java
deleted file mode 100644
index e38386f162cdb..0000000000000
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-
-/**
- *
- * Contains default Log4j implementation for logging.
- */
-
-package org.apache.ignite.logger.log4j;
diff --git a/modules/log4j/src/test/config/log4j-debug.xml b/modules/log4j/src/test/config/log4j-debug.xml
deleted file mode 100644
index 2c361943be031..0000000000000
--- a/modules/log4j/src/test/config/log4j-debug.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/modules/log4j/src/test/config/log4j-info.xml b/modules/log4j/src/test/config/log4j-info.xml
deleted file mode 100644
index 6e6d145e32885..0000000000000
--- a/modules/log4j/src/test/config/log4j-info.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jConfigUpdateTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jConfigUpdateTest.java
deleted file mode 100644
index 64e09a9083fde..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jConfigUpdateTest.java
+++ /dev/null
@@ -1,166 +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.log4j;
-
-import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.StandardCopyOption;
-import java.util.Date;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.log4j.helpers.FileWatchdog;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Checking that Log4j configuration is updated when its source file is changed.
- */
-public class GridLog4jConfigUpdateTest {
- /** Path to log4j configuration with INFO enabled. */
- private static final String LOG_CONFIG_INFO = "modules/log4j/src/test/config/log4j-info.xml";
-
- /** Path to log4j configuration with DEBUG enabled. */
- private static final String LOG_CONFIG_DEBUG = "modules/log4j/src/test/config/log4j-debug.xml";
-
- /** Path to log4j configuration with DEBUG enabled. */
- private static final String LOG_CONFIG_MAIN = "work/log/log4j-GridLog4jConfigUpdateTest.xml";
-
- /** Path to log file. */
- private static final String LOG_DEST = "work/log/GridLog4jConfigUpdateTest.log";
-
- /**
- * Time to wait before updating the configuration file.
- * Should be large enough to be recorded on different file systems.
- */
- private static final int DELAY_BEFORE_MODIFICATION = 5000;
-
- /**
- * Check that changing log4j config file causes the logger configuration to be updated.
- * String-accepting constructor is used.
- */
- @Test
- public void testConfigChangeStringConstructor() throws Exception {
- checkConfigUpdate(new Log4JLoggerSupplier() {
- @Override public Log4JLogger get(File cfgFile) throws Exception {
- return new Log4JLogger(cfgFile.getPath(), 10);
- }
- }, 5000); // use larger delay to avoid relying on exact timing
- }
-
- /**
- * Check that changing log4j config file causes the logger configuration to be updated.
- * String-accepting constructor is used.
- */
- @Test
- public void testConfigChangeStringConstructorDefaultDelay() throws Exception {
- checkConfigUpdate(new Log4JLoggerSupplier() {
- @Override public Log4JLogger get(File cfgFile) throws Exception {
- return new Log4JLogger(cfgFile.getPath());
- }
- }, FileWatchdog.DEFAULT_DELAY + 5000); // use larger delay to avoid relying on exact timing
- }
-
- /**
- * Check that changing log4j config file causes the logger configuration to be updated.
- * File-accepting constructor is used.
- */
- @Test
- public void testConfigChangeFileConstructor() throws Exception {
- checkConfigUpdate(new Log4JLoggerSupplier() {
- @Override public Log4JLogger get(File cfgFile) throws Exception {
- return new Log4JLogger(cfgFile, 10);
- }
- }, 5000); // use larger delay to avoid relying on exact timing
- }
-
- /**
- * Check that changing log4j config file causes the logger configuration to be updated.
- * File-accepting constructor is used.
- */
- @Test
- public void testConfigChangeUrlConstructor() throws Exception {
- checkConfigUpdate(new Log4JLoggerSupplier() {
- @Override public Log4JLogger get(File cfgFile) throws Exception {
- return new Log4JLogger(cfgFile.toURI().toURL(), 10);
- }
- }, 5000); // use larger delay to avoid relying on exact timing
- }
-
- /**
- * Checks that Log4JLogger is updated after configuration file is changed.
- *
- * @param logSupplier Function returning a logger instance to be tested.
- * @param delay time to wait after configuration file has been changed.
- */
- @SuppressWarnings("ResultOfMethodCallIgnored")
- private void checkConfigUpdate(Log4JLoggerSupplier logSupplier, long delay) throws Exception {
- Log4JLogger.cleanup();
-
- File infoCfgFile = new File(U.getIgniteHome(), LOG_CONFIG_INFO);
- File debugCfgFile = new File(U.getIgniteHome(), LOG_CONFIG_DEBUG);
- File mainCfgFile = new File(U.getIgniteHome(), LOG_CONFIG_MAIN);
- File logFile = new File(U.getIgniteHome(), LOG_DEST);
-
- System.out.println("INFO config: " + infoCfgFile);
- System.out.println("DEBUG config: " + debugCfgFile);
- System.out.println("Main config: " + mainCfgFile);
- System.out.println("Log file: " + logFile);
-
- if (logFile.delete())
- System.out.println("Old log file was deleted.");
-
- // Install INFO config.
- mainCfgFile.getParentFile().mkdirs();
- Files.copy(infoCfgFile.toPath(), mainCfgFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
- mainCfgFile.setLastModified(new Date().getTime());
-
- Log4JLogger log = logSupplier.get(mainCfgFile);
-
- log.info("Accepted info");
- log.debug("Ignored debug");
-
- // Wait a bit before copying the file so that new modification date is guaranteed to be different.
- Thread.sleep(DELAY_BEFORE_MODIFICATION);
-
- // Replace current config with DEBUG config.
- Files.copy(debugCfgFile.toPath(), mainCfgFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
- mainCfgFile.setLastModified(new Date().getTime());
-
- // Wait for the update to happen.
- Thread.sleep(delay);
-
- log.debug("Accepted debug");
-
- String logContent = U.readFileToString(logFile.getPath(), "UTF-8");
-
- assertTrue(logContent.contains("[INFO] Accepted info"));
- assertFalse(logContent.contains("[DEBUG] Ignored debug"));
- assertTrue(logContent.contains("[DEBUG] Accepted debug"));
-
- mainCfgFile.delete();
- Log4JLogger.cleanup();
- }
-
- /** Creates Log4JLogger instance for testing. */
- private interface Log4JLoggerSupplier {
- /** Creates Log4JLogger instance for testing. */
- Log4JLogger get(File cfgFile) throws Exception;
- }
-
-}
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jCorrectFileNameTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jCorrectFileNameTest.java
deleted file mode 100644
index f166c000e6313..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jCorrectFileNameTest.java
+++ /dev/null
@@ -1,155 +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.log4j;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.Enumeration;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.typedef.G;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.varia.LevelRangeFilter;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests that several grids log to files with correct names.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4jCorrectFileNameTest {
- /** Appender */
- private Log4jRollingFileAppender appender;
-
- /** */
- @Before
- public void setUp() {
- Logger root = Logger.getRootLogger();
-
- for (Enumeration appenders = root.getAllAppenders(); appenders.hasMoreElements(); ) {
- if (appenders.nextElement() instanceof Log4jRollingFileAppender)
- return;
- }
-
- appender = createAppender();
-
- root.addAppender(appender);
- }
-
- /** */
- @After
- public void tearDown() {
- if (appender != null) {
- Logger.getRootLogger().removeAppender(Log4jRollingFileAppender.class.getSimpleName());
-
- Log4JLogger.removeAppender(appender);
- }
- }
-
- /**
- * Tests correct behaviour in case 2 local nodes are started.
- *
- * @throws Exception If error occurs.
- */
- @Test
- 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 {
- try (Ignite ignite = G.start(getConfiguration("grid" + id))) {
- String id8 = U.id8(ignite.cluster().localNode().id());
- String logPath = "work/log/ignite-" + id8 + ".log";
- File logFile = U.resolveIgnitePath(logPath);
-
- assertNotNull("Failed to resolve path: " + logPath, logFile);
- assertTrue("Log file does not exist: " + logFile, logFile.exists());
-
- 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 igniteInstanceName Ignite instance name.
- * @return Grid configuration.
- */
- private static IgniteConfiguration getConfiguration(String igniteInstanceName) {
- IgniteConfiguration cfg = new IgniteConfiguration();
-
- cfg.setIgniteInstanceName(igniteInstanceName);
- cfg.setGridLogger(new Log4JLogger());
- cfg.setConnectorConfiguration(null);
-
- TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
- TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(false);
-
- ipFinder.setAddresses(Collections.singleton("127.0.0.1:47500..47502"));
-
- disco.setIpFinder(ipFinder);
-
- cfg.setDiscoverySpi(disco);
-
- return cfg;
- }
-
- /**
- * Creates new GridLog4jRollingFileAppender.
- *
- * @return GridLog4jRollingFileAppender.
- */
- private static Log4jRollingFileAppender createAppender() {
- Log4jRollingFileAppender appender = new Log4jRollingFileAppender();
-
- appender.setLayout(new PatternLayout("[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"));
- appender.setFile("work/log/ignite.log");
- appender.setName(Log4jRollingFileAppender.class.getSimpleName());
-
- LevelRangeFilter lvlFilter = new LevelRangeFilter();
-
- lvlFilter.setLevelMin(Level.DEBUG);
- lvlFilter.setLevelMax(Level.INFO);
-
- appender.addFilter(lvlFilter);
-
- return appender;
- }
-}
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jInitializedTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jInitializedTest.java
deleted file mode 100644
index 5b138b08797d2..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jInitializedTest.java
+++ /dev/null
@@ -1,62 +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.log4j;
-
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-import org.apache.log4j.BasicConfigurator;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Log4j initialized test.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4jInitializedTest {
- /** */
- @Before
- public void setUp() {
- BasicConfigurator.configure();
- }
-
- /** */
- @Test
- public void testLogInitialize() {
- IgniteLogger log = new Log4JLogger();
-
- System.out.println(log.toString());
-
- assertTrue(log.toString().contains("Log4JLogger"));
- assertTrue(log.toString().contains("config=null"));
-
- assertTrue(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.");
- log.error("This is 'error' message.", new Exception("It's a test error exception"));
-
- assert log.getLogger(GridLog4jInitializedTest.class.getName()) instanceof Log4JLogger;
- }
-}
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingFileTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingFileTest.java
deleted file mode 100644
index d609b112185f9..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingFileTest.java
+++ /dev/null
@@ -1,70 +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.log4j;
-
-import java.io.File;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Grid Log4j SPI test.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4jLoggingFileTest {
- /** */
- private IgniteLogger log;
-
- /** Logger config */
- private File xml;
-
- /** */
- @Before
- public void setUp() throws Exception {
- xml = GridTestUtils.resolveIgnitePath("modules/core/src/test/config/log4j-test.xml");
-
- assert xml != null;
- assert xml.exists();
-
- log = new Log4JLogger(xml).getLogger(getClass());
- }
-
- /**
- * Tests log4j logging SPI.
- */
- @Test
- public void testLog() {
- System.out.println(log.toString());
-
- assertTrue(log.toString().contains("Log4JLogger"));
- assertTrue(log.toString().contains(xml.getPath()));
-
- assertTrue(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"));
- }
-}
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingPathTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingPathTest.java
deleted file mode 100644
index b4840a41925d1..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingPathTest.java
+++ /dev/null
@@ -1,65 +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.log4j;
-
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Grid Log4j SPI test.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4jLoggingPathTest {
- /** */
- private IgniteLogger log;
-
- /** Logger config */
- private String path = "modules/core/src/test/config/log4j-test.xml";
-
- /** */
- @Before
- public void setUp() throws Exception {
- log = new Log4JLogger(path).getLogger(getClass());
- }
-
- /**
- * Tests log4j logging SPI.
- */
- @Test
- public void testLog() {
- System.out.println(log.toString());
-
- assertTrue(log.toString().contains("Log4JLogger"));
- assertTrue(log.toString().contains(path));
-
- assertTrue(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.");
- log.error("This is 'error' message.", new Exception("It's a test error exception"));
- }
-}
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingUrlTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingUrlTest.java
deleted file mode 100644
index e76625adc5f57..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingUrlTest.java
+++ /dev/null
@@ -1,72 +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.log4j;
-
-import java.io.File;
-import java.net.URL;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Grid Log4j SPI test.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4jLoggingUrlTest {
- /** */
- private IgniteLogger log;
-
- /** Logger config */
- private URL url;
-
- /** */
- @Before
- public void setUp() throws Exception {
- File xml = GridTestUtils.resolveIgnitePath("modules/core/src/test/config/log4j-test.xml");
-
- assert xml != null;
- assert xml.exists();
-
- url = xml.toURI().toURL();
- log = new Log4JLogger(url).getLogger(getClass());
- }
-
- /**
- * Tests log4j logging SPI.
- */
- @Test
- public void testLog() {
- System.out.println(log.toString());
-
- assertTrue(log.toString().contains("Log4JLogger"));
- assertTrue(log.toString().contains(url.getPath()));
-
- assertTrue(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"));
- }
-}
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jNotInitializedTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jNotInitializedTest.java
deleted file mode 100644
index eefebbb8f7745..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jNotInitializedTest.java
+++ /dev/null
@@ -1,54 +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.log4j;
-
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Log4j not initialized test.
- */
-@GridCommonTest(group = "Logger")
-public class GridLog4jNotInitializedTest {
- /** */
- @Test
- public void testLogInitialize() {
- IgniteLogger log = new Log4JLogger().getLogger(GridLog4jNotInitializedTest.class);
-
- System.out.println(log.toString());
-
- assertTrue(log.toString().contains("Log4JLogger"));
- assertTrue(log.toString().contains("config=null"));
-
- 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.");
- }
-}
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jWatchDelayTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jWatchDelayTest.java
deleted file mode 100644
index f9306fe5b796b..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jWatchDelayTest.java
+++ /dev/null
@@ -1,49 +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.log4j;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import org.apache.ignite.IgniteCheckedException;
-import org.junit.Test;
-
-/**
- * Checking Log4JLogger constructors accepting watchDelay parameter.
- */
-public class GridLog4jWatchDelayTest {
- /** Path to log4j configuration file. */
- private static final String LOG_CONFIG = "modules/log4j/src/test/config/log4j-info.xml";
-
- /** Check negative watchDelay in String constructor. */
- @Test(expected = IgniteCheckedException.class)
- public void testNegativeWatchDelayString() throws IgniteCheckedException {
- new Log4JLogger(LOG_CONFIG, -1);
- }
-
- /** Check negative watchDelay in String constructor. */
- @Test(expected = IgniteCheckedException.class)
- public void testNegativeWatchDelayFile() throws IgniteCheckedException {
- new Log4JLogger(new File(LOG_CONFIG), -1);
- }
-
- /** Check negative watchDelay in String constructor. */
- @Test(expected = IgniteCheckedException.class)
- public void testNegativeWatchDelayUrl() throws IgniteCheckedException, MalformedURLException {
- new Log4JLogger(new File(LOG_CONFIG).toURI().toURL(), -1);
- }
-}
diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/package-info.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/package-info.java
deleted file mode 100644
index a00e1148f04f8..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-
-/**
- *
- * Contains internal tests or test related classes and interfaces.
- */
-
-package org.apache.ignite.logger.log4j;
diff --git a/modules/log4j/src/test/java/org/apache/ignite/testsuites/IgniteLog4jTestSuite.java b/modules/log4j/src/test/java/org/apache/ignite/testsuites/IgniteLog4jTestSuite.java
deleted file mode 100644
index c7a099c16c0f2..0000000000000
--- a/modules/log4j/src/test/java/org/apache/ignite/testsuites/IgniteLog4jTestSuite.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.testsuites;
-
-import org.apache.ignite.logger.log4j.GridLog4jConfigUpdateTest;
-import org.apache.ignite.logger.log4j.GridLog4jCorrectFileNameTest;
-import org.apache.ignite.logger.log4j.GridLog4jInitializedTest;
-import org.apache.ignite.logger.log4j.GridLog4jLoggingFileTest;
-import org.apache.ignite.logger.log4j.GridLog4jLoggingPathTest;
-import org.apache.ignite.logger.log4j.GridLog4jLoggingUrlTest;
-import org.apache.ignite.logger.log4j.GridLog4jNotInitializedTest;
-import org.apache.ignite.logger.log4j.GridLog4jWatchDelayTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Log4j logging tests.
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- GridLog4jInitializedTest.class,
- GridLog4jNotInitializedTest.class,
- GridLog4jCorrectFileNameTest.class,
- GridLog4jLoggingFileTest.class,
- GridLog4jLoggingPathTest.class,
- GridLog4jLoggingUrlTest.class,
- GridLog4jConfigUpdateTest.class,
- GridLog4jWatchDelayTest.class,
-})
-public class IgniteLog4jTestSuite { }
diff --git a/modules/log4j2/README.txt b/modules/log4j2/README.txt
index 6e21b7a024d88..ade743d056598 100644
--- a/modules/log4j2/README.txt
+++ b/modules/log4j2/README.txt
@@ -14,7 +14,7 @@ To enable ignite logging with default configuration use:
...
-
+
...
diff --git a/modules/log4j2/pom.xml b/modules/log4j2/pom.xml
index fb9faae71430e..2cba3ad2291ed 100644
--- a/modules/log4j2/pom.xml
+++ b/modules/log4j2/pom.xml
@@ -56,13 +56,11 @@
org.apache.logging.log4j
log4j-api
- ${log4j2.version}
org.apache.logging.log4j
log4j-core
- ${log4j2.version}
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 954c7c891580d..2dde4fdad1c40 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
@@ -33,10 +33,10 @@
import org.apache.ignite.logger.LoggerNodeIdAndApplicationAware;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.appender.FileAppender;
@@ -45,11 +45,19 @@
import org.apache.logging.log4j.core.config.AppenderControl;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
+import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
+import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.jetbrains.annotations.Nullable;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_CONSOLE_APPENDER;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET;
+import static org.apache.logging.log4j.core.appender.ConsoleAppender.Target.SYSTEM_ERR;
+import static org.apache.logging.log4j.core.appender.ConsoleAppender.Target.SYSTEM_OUT;
/**
* Log4j2-based implementation for logging. This logger should be used
@@ -59,7 +67,7 @@
*
* <property name="gridLogger">
* <bean class="org.apache.ignite.logger.log4j2.Log4J2Logger">
- * <constructor-arg type="java.lang.String" value="config/ignite-log4j2.xml"/>
+ * <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/>
* </bean>
* </property>
*
@@ -115,10 +123,22 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAndApplicationAwa
@GridToStringExclude
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, otherwise, existing appenders will be used.
+ */
+ public Log4J2Logger() {
+ addConsoleAppenderIfNeeded(init -> LogManager.getRootLogger());
+
+ quiet = quiet0;
+ cfg = null;
+ }
+
/**
* Creates new logger with given implementation.
*
- * @param impl Log4j implementation to use.
+ * @param impl Log4j2 implementation to use.
*/
private Log4J2Logger(final Logger impl, String path) {
assert impl != null;
@@ -151,9 +171,9 @@ public Log4J2Logger(String path) throws IgniteCheckedException {
addConsoleAppenderIfNeeded(new C1() {
@Override public Logger apply(Boolean init) {
if (init)
- Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
+ Configurator.initialize(LoggerConfig.ROOT, cfgUrl.toString());
- return (Logger)LogManager.getRootLogger();
+ return LogManager.getRootLogger();
}
});
@@ -179,9 +199,9 @@ public Log4J2Logger(File cfgFile) throws IgniteCheckedException {
addConsoleAppenderIfNeeded(new C1() {
@Override public Logger apply(Boolean init) {
if (init)
- Configurator.initialize(LogManager.ROOT_LOGGER_NAME, path);
+ Configurator.initialize(LoggerConfig.ROOT, path);
- return (Logger)LogManager.getRootLogger();
+ return LogManager.getRootLogger();
}
});
@@ -202,9 +222,9 @@ public Log4J2Logger(final URL cfgUrl) throws IgniteCheckedException {
addConsoleAppenderIfNeeded(new C1() {
@Override public Logger apply(Boolean init) {
if (init)
- Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
+ Configurator.initialize(LoggerConfig.ROOT, cfgUrl.toString());
- return (Logger)LogManager.getRootLogger();
+ return LogManager.getRootLogger();
}
});
@@ -227,8 +247,10 @@ static void cleanup() {
/** {@inheritDoc} */
@Nullable @Override public String fileName() {
- for (Logger log = impl; log != null; log = log.getParent()) {
- for (Appender a : log.getAppenders().values()) {
+ Configuration cfg = LoggerContext.getContext(false).getConfiguration();
+
+ for (LoggerConfig logCfg = cfg.getLoggerConfig(impl.getName()); logCfg != null; logCfg = logCfg.getParent()) {
+ for (Appender a : logCfg.getAppenders().values()) {
if (a instanceof FileAppender)
return ((FileAppender)a).getFileName();
@@ -294,46 +316,17 @@ private void addConsoleAppenderIfNeeded(@Nullable IgniteClosure
// Init logger impl.
impl = initLogClo.apply(true);
- boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
-
- boolean consoleAppenderFound = false;
- Logger rootLogger = 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()))
- continue;
-
- consoleAppenderFound = true;
-
- break;
- }
- }
- }
-
- if (log.getParent() == null) {
- rootLogger = log;
+ boolean quiet = Boolean.parseBoolean(System.getProperty(IGNITE_QUIET, "true"));
- break;
- }
- else
- log = log.getParent();
- }
+ boolean consoleAppenderFound = isConsoleAppenderConfigured();
if (consoleAppenderFound && quiet)
- // 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;
+ quiet = false; // User configured console appender, but log is quiet.
+ if (!consoleAppenderFound && !quiet && Boolean.parseBoolean(System.getProperty(IGNITE_CONSOLE_APPENDER, "true"))) {
// 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.
- createConsoleLogger();
+ configureConsoleAppender();
}
quiet0 = quiet;
@@ -341,39 +334,86 @@ private void addConsoleAppenderIfNeeded(@Nullable IgniteClosure
}
}
+ /** */
+ private boolean isConsoleAppenderConfigured() {
+ Configuration cfg = LoggerContext.getContext(false).getConfiguration();
+
+ if (cfg instanceof DefaultConfiguration)
+ return false;
+
+ for (LoggerConfig logCfg = cfg.getLoggerConfig(impl.getName()); logCfg != null; logCfg = logCfg.getParent()) {
+ for (Appender appender : logCfg.getAppenders().values()) {
+ if (appender instanceof ConsoleAppender) {
+ if (((ConsoleAppender)appender).getTarget() == SYSTEM_ERR)
+ continue;
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
/**
* Creates console appender with some reasonable default logging settings.
*
* @return Logger with auto configured console appender.
*/
- public Logger createConsoleLogger() {
+ public Logger configureConsoleAppender() {
// from http://logging.apache.org/log4j/2.x/manual/customconfig.html
- final LoggerContext ctx = impl.getContext();
+ LoggerContext ctx = LoggerContext.getContext(false);
+
+ Configuration cfg = ctx.getConfiguration();
+
+ if (cfg instanceof DefaultConfiguration) {
+ ConfigurationBuilder cfgBuilder = ConfigurationBuilderFactory.newConfigurationBuilder();
+
+ RootLoggerComponentBuilder rootLog = cfgBuilder.newRootLogger(Level.INFO);
+
+ cfg = cfgBuilder.add(rootLog).build();
+
+ addConsoleAppender(cfg);
+
+ ctx.reconfigure(cfg);
+ }
+ else {
+ addConsoleAppender(cfg);
+
+ ctx.updateLoggers();
+ }
- final Configuration cfg = ctx.getConfiguration();
+ return ctx.getRootLogger();
+ }
- PatternLayout.Builder builder = PatternLayout.newBuilder()
+ /** */
+ private void addConsoleAppender(Configuration logCfg) {
+ PatternLayout layout = PatternLayout.newBuilder()
.withPattern("%d{ISO8601}][%-5p][%t][%c{1}] %m%n")
.withCharset(Charset.defaultCharset())
.withAlwaysWriteExceptions(false)
- .withNoConsoleNoAnsi(false);
+ .withNoConsoleNoAnsi(false)
+ .build();
- PatternLayout layout = builder.build();
-
- ConsoleAppender.Builder consoleAppenderBuilder = ConsoleAppender.newBuilder()
- .withName(CONSOLE_APPENDER)
- .withLayout(layout);
-
- ConsoleAppender consoleApp = consoleAppenderBuilder.build();
+ ConsoleAppender consoleApp = ConsoleAppender.newBuilder()
+ .setTarget(SYSTEM_OUT)
+ .setName(CONSOLE_APPENDER)
+ .setLayout(layout)
+ .build();
consoleApp.start();
- cfg.addAppender(consoleApp);
- cfg.getRootLogger().addAppender(consoleApp, Level.TRACE, null);
-
- ctx.updateLoggers(cfg);
+ logCfg.addAppender(consoleApp);
+ logCfg.getRootLogger().addAppender(consoleApp, Level.TRACE, null);
+ }
- return ctx.getRootLogger();
+ /**
+ * Checks if Log4j is already configured within this VM or not.
+ *
+ * @return {@code True} if log4j was already configured, {@code false} otherwise.
+ */
+ public static boolean isConfigured() {
+ return !(LoggerContext.getContext(false).getConfiguration() instanceof DefaultConfiguration);
}
/** {@inheritDoc} */
@@ -387,8 +427,6 @@ public Logger createConsoleLogger() {
System.setProperty(APP_ID, application != null ? application : "ignite");
if (inited) {
- final LoggerContext ctx = impl.getContext();
-
synchronized (mux) {
inited = false;
}
@@ -396,9 +434,9 @@ public Logger createConsoleLogger() {
addConsoleAppenderIfNeeded(new C1() {
@Override public Logger apply(Boolean init) {
if (init)
- ctx.reconfigure();
+ LoggerContext.getContext(false).reconfigure();
- return (Logger)LogManager.getRootLogger();
+ return LogManager.getRootLogger();
}
});
}
@@ -420,17 +458,17 @@ public Logger createConsoleLogger() {
*/
@Override public Log4J2Logger getLogger(Object ctgr) {
if (ctgr == null)
- return new Log4J2Logger((Logger)LogManager.getRootLogger(), cfg);
+ return new Log4J2Logger(LogManager.getRootLogger(), cfg);
if (ctgr instanceof Class) {
String name = ((Class>)ctgr).getName();
- return new Log4J2Logger((Logger)LogManager.getLogger(name), cfg);
+ return new Log4J2Logger(LogManager.getLogger(name), cfg);
}
String name = ctgr.toString();
- return new Log4J2Logger((Logger)LogManager.getLogger(name), cfg);
+ return new Log4J2Logger(LogManager.getLogger(name), cfg);
}
/** {@inheritDoc} */
diff --git a/config/ignite-log4j2.xml b/modules/log4j2/src/test/config/log4j2-test.xml
similarity index 63%
rename from config/ignite-log4j2.xml
rename to modules/log4j2/src/test/config/log4j2-test.xml
index ee4e268927f33..9740c2ce27e08 100644
--- a/config/ignite-log4j2.xml
+++ b/modules/log4j2/src/test/config/log4j2-test.xml
@@ -17,7 +17,7 @@
limitations under the License.
-->
-
+
@@ -28,12 +28,6 @@
-
-
- "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"
-
-
-
@@ -51,40 +45,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
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
index 137cb98d31dcf..6c2571c99f542 100644
--- 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
@@ -42,10 +42,10 @@
*/
public class Log4j2LoggerSelfTest {
/** */
- private static final String LOG_PATH_TEST = "modules/core/src/test/config/log4j2-test.xml";
+ private static final String LOG_PATH_TEST = "modules/log4j2/src/test/config/log4j2-test.xml";
/** */
- private static final String LOG_PATH_MAIN = "config/ignite-log4j2.xml";
+ private static final String LOG_PATH_MAIN = "config/ignite-log4j.xml";
/** */
@Before
diff --git a/modules/ml/pom.xml b/modules/ml/pom.xml
index 9029a9532a034..62e0dad543179 100644
--- a/modules/ml/pom.xml
+++ b/modules/ml/pom.xml
@@ -83,8 +83,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/ml/spark-model-parser/pom.xml b/modules/ml/spark-model-parser/pom.xml
index 7cc7ebd77f93e..eed310ba5db27 100644
--- a/modules/ml/spark-model-parser/pom.xml
+++ b/modules/ml/spark-model-parser/pom.xml
@@ -86,6 +86,10 @@
hadoop-common
2.9.1
+
+ log4j
+ log4j
+
org.slf4j
slf4j-log4j12
diff --git a/modules/numa-allocator/pom.xml b/modules/numa-allocator/pom.xml
index 62cfa2c2619bd..b9b3f04c3212b 100644
--- a/modules/numa-allocator/pom.xml
+++ b/modules/numa-allocator/pom.xml
@@ -83,8 +83,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/opencensus/pom.xml b/modules/opencensus/pom.xml
index f556f84c68ee3..87f38880e75ec 100644
--- a/modules/opencensus/pom.xml
+++ b/modules/opencensus/pom.xml
@@ -55,7 +55,7 @@
${project.groupId}
- ignite-log4j
+ ignite-log4j2
test
diff --git a/modules/platforms/cpp/core-test/src/test_utils.cpp b/modules/platforms/cpp/core-test/src/test_utils.cpp
index a123a46f13074..fe96cdc298d28 100644
--- a/modules/platforms/cpp/core-test/src/test_utils.cpp
+++ b/modules/platforms/cpp/core-test/src/test_utils.cpp
@@ -55,6 +55,8 @@ namespace ignite_test
assert(cfgFile != 0);
+ cfg.igniteHome = jni::ResolveIgniteHome();
+
cfg.jvmOpts.push_back("-Xdebug");
cfg.jvmOpts.push_back("-Xnoagent");
cfg.jvmOpts.push_back("-Djava.compiler=NONE");
@@ -65,8 +67,8 @@ namespace ignite_test
cfg.jvmOpts.push_back("-DIGNITE_UPDATE_NOTIFIER=false");
cfg.jvmOpts.push_back("-DIGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP=false");
cfg.jvmOpts.push_back("-Duser.language=en");
+ cfg.jvmOpts.push_back("-Dlog4j.configurationFile=" + cfg.igniteHome + "/modules/core/src/test/config/log4j2-test.xml");
- cfg.igniteHome = jni::ResolveIgniteHome();
cfg.jvmClassPath = jni::CreateIgniteHomeClasspath(cfg.igniteHome, true);
#ifdef IGNITE_TESTS_32
diff --git a/modules/platforms/cpp/odbc-test/src/test_utils.cpp b/modules/platforms/cpp/odbc-test/src/test_utils.cpp
index 0f1affd2f6129..05d93ab0e3ec6 100644
--- a/modules/platforms/cpp/odbc-test/src/test_utils.cpp
+++ b/modules/platforms/cpp/odbc-test/src/test_utils.cpp
@@ -105,6 +105,8 @@ namespace ignite_test
assert(cfgFile != 0);
+ cfg.igniteHome = jni::ResolveIgniteHome();
+
cfg.jvmOpts.push_back("-Xdebug");
cfg.jvmOpts.push_back("-Xnoagent");
cfg.jvmOpts.push_back("-Djava.compiler=NONE");
@@ -115,10 +117,10 @@ namespace ignite_test
cfg.jvmOpts.push_back("-DIGNITE_UPDATE_NOTIFIER=false");
cfg.jvmOpts.push_back("-DIGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP=false");
cfg.jvmOpts.push_back("-Duser.language=en");
+ cfg.jvmOpts.push_back("-Dlog4j.configurationFile=" + cfg.igniteHome + "/modules/core/src/test/config/log4j2-test.xml");
// Un-comment to debug SSL
//cfg.jvmOpts.push_back("-Djavax.net.debug=ssl");
- cfg.igniteHome = jni::ResolveIgniteHome();
cfg.jvmClassPath = jni::CreateIgniteHomeClasspath(cfg.igniteHome, true);
#ifdef IGNITE_TESTS_32
diff --git a/modules/platforms/cpp/thin-client-test/config/with-logging-0.xml b/modules/platforms/cpp/thin-client-test/config/with-logging-0.xml
index 3a52964beabc5..6e99ac2b29ef6 100644
--- a/modules/platforms/cpp/thin-client-test/config/with-logging-0.xml
+++ b/modules/platforms/cpp/thin-client-test/config/with-logging-0.xml
@@ -28,7 +28,12 @@
-
+
+
diff --git a/modules/platforms/cpp/thin-client-test/src/test_utils.cpp b/modules/platforms/cpp/thin-client-test/src/test_utils.cpp
index 468cc36e47d17..04a5f71a07f89 100644
--- a/modules/platforms/cpp/thin-client-test/src/test_utils.cpp
+++ b/modules/platforms/cpp/thin-client-test/src/test_utils.cpp
@@ -59,6 +59,8 @@ namespace ignite_test
assert(cfgFile != 0);
+ cfg.igniteHome = jni::ResolveIgniteHome();
+
cfg.jvmOpts.push_back("-Xdebug");
cfg.jvmOpts.push_back("-Xnoagent");
cfg.jvmOpts.push_back("-Djava.compiler=NONE");
@@ -69,10 +71,10 @@ namespace ignite_test
cfg.jvmOpts.push_back("-DIGNITE_UPDATE_NOTIFIER=false");
cfg.jvmOpts.push_back("-DIGNITE_LOG_CLASSPATH_CONTENT_ON_STARTUP=false");
cfg.jvmOpts.push_back("-Duser.language=en");
+ cfg.jvmOpts.push_back("-Dlog4j.configurationFile=" + cfg.igniteHome + "/modules/core/src/test/config/log4j2-test.xml");
// Un-comment to debug SSL
// cfg.jvmOpts.push_back("-Djavax.net.debug=ssl");
- cfg.igniteHome = jni::ResolveIgniteHome();
cfg.jvmClassPath = jni::CreateIgniteHomeClasspath(cfg.igniteHome, true);
#ifdef IGNITE_TESTS_32
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/custom-log.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/custom-log.xml
index 5d7dc658006a1..8a3491d8f0e25 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/custom-log.xml
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/custom-log.xml
@@ -26,7 +26,7 @@
-
+
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/dotnet-log4j.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/dotnet-log4j.xml
index 9d6aefdf72f88..f881b038ca0e8 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/dotnet-log4j.xml
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Log/dotnet-log4j.xml
@@ -17,127 +17,68 @@
limitations under the License.
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/DefaultLoggerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/DefaultLoggerTest.cs
index fd84cb7fa7bdb..09856a38ce906 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/DefaultLoggerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/DefaultLoggerTest.cs
@@ -98,11 +98,11 @@ public void TestJavaLogger()
Assert.IsTrue(log.Contains("[DEBUG][main][=DOTNET=] DOTNET-Debug"));
Assert.IsTrue(log.Contains("[WARN ][main][=DOTNET=] DOTNET-Warn"));
- Assert.IsTrue(log.Contains("class org.apache.ignite.IgniteException: " +
+ Assert.IsTrue(log.Contains("org.apache.ignite.IgniteException: " +
"Platform error:System.Exception: EXCEPTION_TEST_Warn"));
Assert.IsTrue(log.Contains("[ERROR][main][=DOTNET=] DOTNET-Error"));
- Assert.IsTrue(log.Contains("class org.apache.ignite.IgniteException: " +
+ Assert.IsTrue(log.Contains("org.apache.ignite.IgniteException: " +
"Platform error:System.Exception: EXCEPTION_TEST_Error"));
}
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
index 2ab05940185d3..5e729bfe064a1 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs
@@ -137,6 +137,8 @@ public static IList TestJavaOptions(bool? jvmDebug = null)
foreach (string opt in JvmDebugOpts)
ops.Add(opt);
}
+
+ ops.Add("-Dlog4j.configurationFile=" + IgniteHome.Resolve() + "/modules/core/src/test/config/log4j2-test.xml");
return ops;
}
diff --git a/modules/rest-http/pom.xml b/modules/rest-http/pom.xml
index 31b0027f9e18f..f326f428621be 100644
--- a/modules/rest-http/pom.xml
+++ b/modules/rest-http/pom.xml
@@ -120,8 +120,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
index c0c63c6e9edec..0220395a55e71 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestProtocol.java
@@ -62,35 +62,11 @@ public class GridJettyRestProtocol extends GridRestProtocolAdapter {
*/
static {
if (!IgniteSystemProperties.getBoolean(IGNITE_JETTY_LOG_NO_OVERRIDE)) {
- // See also https://www.eclipse.org/jetty/documentation/9.4.x/configuring-logging.html
+ // See also https://www.eclipse.org/jetty/documentation/jetty-9/index.html#configuring-jetty-logging
// It seems that using system properties should be fine.
System.setProperty("org.eclipse.jetty.LEVEL", "WARN");
System.setProperty("org.eclipse.jetty.util.log.LEVEL", "OFF");
System.setProperty("org.eclipse.jetty.util.component.LEVEL", "OFF");
-
- try {
- Class> logCls = Class.forName("org.apache.log4j.Logger");
-
- String ctgrJetty = "org.eclipse.jetty"; // WARN for this category.
- String ctgrJettyUtil = "org.eclipse.jetty.util.log"; // ERROR for this...
- String ctgrJettyUtilComp = "org.eclipse.jetty.util.component"; // ...and this.
-
- Object logJetty = logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJetty);
- Object logJettyUtil = logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJettyUtil);
- Object logJettyUtilComp = logCls.getMethod("getLogger", String.class).invoke(logCls, ctgrJettyUtilComp);
-
- Class> lvlCls = Class.forName("org.apache.log4j.Level");
-
- Object warnLvl = lvlCls.getField("WARN").get(null);
- Object errLvl = lvlCls.getField("ERROR").get(null);
-
- logJetty.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, warnLvl);
- logJettyUtil.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, errLvl);
- logJettyUtilComp.getClass().getMethod("setLevel", lvlCls).invoke(logJetty, errLvl);
- }
- catch (Exception ignored) {
- // No-op.
- }
}
}
diff --git a/modules/schedule/pom.xml b/modules/schedule/pom.xml
index d28da7f4dc0d3..99738be0d98b6 100644
--- a/modules/schedule/pom.xml
+++ b/modules/schedule/pom.xml
@@ -74,8 +74,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/slf4j/pom.xml b/modules/slf4j/pom.xml
index d4f2bd21df01e..6565160d27070 100644
--- a/modules/slf4j/pom.xml
+++ b/modules/slf4j/pom.xml
@@ -62,14 +62,12 @@
org.apache.logging.log4j
log4j-slf4j-impl
- ${log4j2.version}
test
org.apache.logging.log4j
log4j-core
- ${log4j2.version}
test
diff --git a/modules/spring/pom.xml b/modules/spring/pom.xml
index ae6a22c2e184d..76407790d4c52 100644
--- a/modules/spring/pom.xml
+++ b/modules/spring/pom.xml
@@ -65,7 +65,7 @@
${project.groupId}
- ignite-log4j
+ ignite-log4j2
test
diff --git a/modules/ssh/pom.xml b/modules/ssh/pom.xml
index 50dad0668b599..9c61d9d31e3bd 100644
--- a/modules/ssh/pom.xml
+++ b/modules/ssh/pom.xml
@@ -54,7 +54,7 @@
${project.groupId}
- ignite-log4j
+ ignite-log4j2
test
diff --git a/modules/urideploy/pom.xml b/modules/urideploy/pom.xml
index cf8b0f02756b7..360a549829038 100644
--- a/modules/urideploy/pom.xml
+++ b/modules/urideploy/pom.xml
@@ -144,8 +144,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala
index d9e34abff217a..6801c21ae5679 100644
--- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala
+++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/open/VisorOpenCommand.scala
@@ -130,31 +130,18 @@ class VisorOpenCommand extends VisorConsoleCommand {
url
}
- // Add no-op logger to remove no-appender warning.
- val log4jTup =
- if (visor.quiet) {
- val springLog = Logger.getLogger("org.springframework")
+ if (visor.quiet) {
+ val springLog = Logger.getLogger("org.springframework")
- if (springLog != null)
- springLog.setLevel(Level.WARNING)
-
- null
- }
- else if (classOf[Ignition].getClassLoader.getResource("org/apache/log4j/Appender.class") != null)
- U.addLog4jNoOpLogger()
- else
- null
+ if (springLog != null)
+ springLog.setLevel(Level.WARNING)
+ }
val spring: IgniteSpringHelper = SPRING.create(false)
val cfgs =
- try
- // Cache, indexing SPI configurations should be excluded from daemon node config.
- spring.loadConfigurations(url, "cacheConfiguration", "lifecycleBeans", "indexingSpi").get1()
- finally {
- if (log4jTup != null && !visor.quiet)
- U.removeLog4jNoOpLogger(log4jTup)
- }
+ // Cache, indexing SPI configurations should be excluded from daemon node config.
+ spring.loadConfigurations(url, "cacheConfiguration", "lifecycleBeans", "indexingSpi").get1()
if (cfgs == null || cfgs.isEmpty)
throw new IgniteException("Can't find grid configuration in: " + url)
@@ -167,7 +154,7 @@ class VisorOpenCommand extends VisorConsoleCommand {
if (visor.quiet)
cfg.setGridLogger(new NullLogger)
else {
- if (log4jTup != null)
+ if (classOf[Ignition].getClassLoader.getResource("org/apache/logging/log4j/core/Appender.class") != null)
System.setProperty(IgniteSystemProperties.IGNITE_CONSOLE_APPENDER, "false")
else
Logger.getGlobal.getHandlers.foreach({
diff --git a/modules/visor-plugins/pom.xml b/modules/visor-plugins/pom.xml
index ad3a303d4739c..59bb3a9002d59 100644
--- a/modules/visor-plugins/pom.xml
+++ b/modules/visor-plugins/pom.xml
@@ -56,9 +56,8 @@
- org.slf4j
- slf4j-log4j12
- ${slf4j.version}
+ org.apache.logging.log4j
+ log4j-slf4j-impl
diff --git a/modules/visor-plugins/src/main/java/log4j.properties b/modules/visor-plugins/src/main/java/log4j2.properties
similarity index 70%
rename from modules/visor-plugins/src/main/java/log4j.properties
rename to modules/visor-plugins/src/main/java/log4j2.properties
index 092bf9f0f6019..cfc2382906c28 100644
--- a/modules/visor-plugins/src/main/java/log4j.properties
+++ b/modules/visor-plugins/src/main/java/log4j2.properties
@@ -15,11 +15,17 @@
# limitations under the License.
#
+# Configure console appender.
+appender.stdout.type=Console
+appender.stdout.name=stdout
+appender.stdout.target=SYSTEM_ERR
+appender.stdout.layout.type=PatternLayout
+appender.stdout.layout.pattern=[%d{ISO8601}][%-5p][%t][%c{1}] %m%n
+
# Configure pf4j loggers.
-log4j.logger.ro.fortsoft.pf4j=ERROR, stdout
+logger.pf4j.name=ro.fortsoft.pf4j
+logger.pf4j.level=ERROR
+logger.pf4j.appenderRef.$1.ref=stdout
-# Configure console appender.
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Target=System.err
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=[%d{ISO8601}][%-5p][%t][%c{1}] %m%n
+rootLogger.level=info
+rootLogger.appenderRef.$1.ref=stdout
diff --git a/modules/web/ignite-appserver-test/pom.xml b/modules/web/ignite-appserver-test/pom.xml
index c069313a624ff..80438f54c8984 100644
--- a/modules/web/ignite-appserver-test/pom.xml
+++ b/modules/web/ignite-appserver-test/pom.xml
@@ -46,7 +46,7 @@
${project.groupId}
- ignite-log4j
+ ignite-log4j2
diff --git a/modules/web/pom.xml b/modules/web/pom.xml
index 7b96bd99e0af4..a743f5423c9ca 100644
--- a/modules/web/pom.xml
+++ b/modules/web/pom.xml
@@ -86,8 +86,8 @@
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-core
test
diff --git a/modules/yardstick/pom-standalone.xml b/modules/yardstick/pom-standalone.xml
index c0795b005ee17..c667650c325ab 100644
--- a/modules/yardstick/pom-standalone.xml
+++ b/modules/yardstick/pom-standalone.xml
@@ -60,7 +60,7 @@
${project.groupId}
- ignite-log4j
+ ignite-log4j2
${project.version}
diff --git a/modules/yardstick/pom.xml b/modules/yardstick/pom.xml
index f5aff1cf31e4c..7fe1a15225fc8 100644
--- a/modules/yardstick/pom.xml
+++ b/modules/yardstick/pom.xml
@@ -56,7 +56,7 @@
${project.groupId}
- ignite-log4j
+ ignite-log4j2
diff --git a/modules/zookeeper/pom.xml b/modules/zookeeper/pom.xml
index 47cdf40fc6c2a..d823855a62569 100644
--- a/modules/zookeeper/pom.xml
+++ b/modules/zookeeper/pom.xml
@@ -45,6 +45,10 @@
zookeeper
${zookeeper.version}
+
+ log4j
+ log4j
+
org.slf4j
slf4j-log4j12
@@ -65,15 +69,8 @@
- org.slf4j
- slf4j-log4j12
- ${slf4j.version}
- test
-
-
-
- log4j
- log4j
+ org.apache.logging.log4j
+ log4j-slf4j-impl
test
@@ -109,7 +106,7 @@
${project.groupId}
- ignite-log4j
+ ignite-log4j2
test
diff --git a/parent-internal/pom.xml b/parent-internal/pom.xml
index 7e07ba505837e..7b225d14536b1 100644
--- a/parent-internal/pom.xml
+++ b/parent-internal/pom.xml
@@ -47,19 +47,11 @@
- log4j
- log4j
- ${log4j.version}
-
-
- com.sun.jdmk
- jmxtools
-
-
- com.sun.jmx
- jmxri
-
-
+ org.apache.logging.log4j
+ log4j-bom
+ ${log4j2.version}
+ import
+ pom
diff --git a/parent/pom.xml b/parent/pom.xml
index 5827c7aff753d..9cf65b13c97d5 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -116,7 +116,6 @@
r938
2.0.1
2.17.1
- 1.2.17
7.4.0_1
8.11.2
1.8.0
diff --git a/pom.xml b/pom.xml
index 6580e0cdc89f9..1460b082262d9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,7 +55,6 @@
modules/ssh
modules/rest-http
modules/jta
- modules/log4j
modules/log4j2
modules/slf4j
modules/jcl