diff --git a/assembly/libs/README.txt b/assembly/libs/README.txt index cdfd223787e10..c907e01aaaa5d 100644 --- a/assembly/libs/README.txt +++ b/assembly/libs/README.txt @@ -75,7 +75,6 @@ The following modules are available: - ignite-indexing (for SQL querying and indexing) - ignite-jcl (for Apache Commons logging) - ignite-jta (for XA integration) -- ignite-logj4 (for Log4j logging) - ignite-log4j2 (for Log4j 2 logging) - ignite-rest-http (for HTTP REST messages) - ignite-schedule (for Cron-based task scheduling) diff --git a/assembly/release-base.xml b/assembly/release-base.xml index df8598f5453fe..e3bdffe1b155f 100644 --- a/assembly/release-base.xml +++ b/assembly/release-base.xml @@ -42,11 +42,6 @@ /config - - config/ignite-log4j2.xml - /config - - config/java.util.logging.properties /config diff --git a/config/ignite-log4j.xml b/config/ignite-log4j.xml index f53997d1a4b07..ee4e268927f33 100644 --- a/config/ignite-log4j.xml +++ b/config/ignite-log4j.xml @@ -17,134 +17,75 @@ limitations under the License. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n" + + + + + + + + + + + + + + + + + + + + - - - - - + + - - - - - - - + + - - - - + + + - - - - - - + + + + + + + + + + + + + + diff --git a/docs/_docs/code-snippets/java/pom.xml b/docs/_docs/code-snippets/java/pom.xml index e04110205b359..10bd2fcd59528 100644 --- a/docs/_docs/code-snippets/java/pom.xml +++ b/docs/_docs/code-snippets/java/pom.xml @@ -37,11 +37,6 @@ ignite-log4j2 ${ignite.version} - - ${project.groupId} - ignite-log4j - ${ignite.version} - ${project.groupId} ignite-jcl diff --git a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/Logging.java b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/Logging.java index e96998d90e05b..2f8e73106b630 100644 --- a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/Logging.java +++ b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/Logging.java @@ -22,28 +22,10 @@ import org.apache.ignite.Ignition; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.logger.jcl.JclLogger; -import org.apache.ignite.logger.log4j.Log4JLogger; import org.apache.ignite.logger.log4j2.Log4J2Logger; import org.apache.ignite.logger.slf4j.Slf4jLogger; public class Logging { - - void log4j() throws IgniteCheckedException { - - // tag::log4j[] - IgniteConfiguration cfg = new IgniteConfiguration(); - - IgniteLogger log = new Log4JLogger("log4j-config.xml"); - - cfg.setGridLogger(log); - - // Start a node. - try (Ignite ignite = Ignition.start(cfg)) { - ignite.log().info("Info Message Logged!"); - } - // end::log4j[] - } - void log4j2() throws IgniteCheckedException { // tag::log4j2[] IgniteConfiguration cfg = new IgniteConfiguration(); diff --git a/docs/_docs/code-snippets/xml/log4j-config.xml b/docs/_docs/code-snippets/xml/log4j-config.xml deleted file mode 100644 index f8c1a37803980..0000000000000 --- a/docs/_docs/code-snippets/xml/log4j-config.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/_docs/code-snippets/xml/log4j.xml b/docs/_docs/code-snippets/xml/log4j.xml deleted file mode 100644 index fdb6203bc8a08..0000000000000 --- a/docs/_docs/code-snippets/xml/log4j.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - 127.0.0.1:47500..47509 - - - - - - - - - - diff --git a/docs/_docs/extensions-and-integrations/ignite-for-spark/installation.adoc b/docs/_docs/extensions-and-integrations/ignite-for-spark/installation.adoc index 05cdf643cfa6d..730ec590effce 100644 --- a/docs/_docs/extensions-and-integrations/ignite-for-spark/installation.adoc +++ b/docs/_docs/extensions-and-integrations/ignite-for-spark/installation.adoc @@ -120,7 +120,7 @@ The following shows how to fill in `spark.driver.extraClassPath` parameters: [source, shell] ---- -spark.executor.extraClassPath /opt/ignite/libs/*:/opt/ignite/libs/optional/ignite-spark-ext/*:/opt/ignite/libs/optional/ignite-log4j/*:/opt/ignite/libs/optional/ignite-yarn-ext/*:/opt/ignite/libs/ignite-spring/* +spark.executor.extraClassPath /opt/ignite/libs/*:/opt/ignite/libs/optional/ignite-spark-ext/*:/opt/ignite/libs/optional/ignite-log4j2/*:/opt/ignite/libs/optional/ignite-yarn-ext/*:/opt/ignite/libs/ignite-spring/* ---- === Source Code Configuration diff --git a/docs/_docs/extensions-and-integrations/ignite-for-spark/spark-shell.adoc b/docs/_docs/extensions-and-integrations/ignite-for-spark/spark-shell.adoc index 37bcab6596965..25c21f41ba215 100644 --- a/docs/_docs/extensions-and-integrations/ignite-for-spark/spark-shell.adoc +++ b/docs/_docs/extensions-and-integrations/ignite-for-spark/spark-shell.adoc @@ -70,7 +70,7 @@ Now that you have your cluster up and running, you can run `spark-shell` and che + [source, shell] ---- -./bin/spark-shell --jars path/to/ignite-core.jar,path/to/ignite-spark-ext.jar,path/to/cache-api.jar,path/to/ignite-log4j.jar,path/to/log4j.jar --master spark://master_host:master_port +./bin/spark-shell --jars path/to/ignite-core.jar,path/to/ignite-spark-ext.jar,path/to/cache-api.jar,path/to/ignite-log4j2.jar,path/to/log4j.jar --master spark://master_host:master_port ---- You should see Spark shell started up. diff --git a/docs/_docs/extensions-and-integrations/ignite-for-spark/troubleshooting.adoc b/docs/_docs/extensions-and-integrations/ignite-for-spark/troubleshooting.adoc index f083081627460..2072d301b0c4c 100644 --- a/docs/_docs/extensions-and-integrations/ignite-for-spark/troubleshooting.adoc +++ b/docs/_docs/extensions-and-integrations/ignite-for-spark/troubleshooting.adoc @@ -20,4 +20,4 @@ This will happen if you have created `IgniteContext` in client mode (which is de * I am getting `java.lang.ClassNotFoundException` `org.apache.ignite.logger.java.JavaLoggerFileHandler` when using IgniteContext -This issue appears when you do not have any loggers included in classpath and Ignite tries to use standard Java logging. By default Spark loads all user jar files using separate class loader. Java logging framework, on the other hand, uses application class loader to initialize log handlers. To resolve this, you can either add `ignite-log4j` module to the list of the used jars so that Ignite would use Log4j as a logging subsystem, or alter default Spark classpath as described link:ignite-for-spark/installation[here]. +This issue appears when you do not have any loggers included in classpath and Ignite tries to use standard Java logging. By default Spark loads all user jar files using separate class loader. Java logging framework, on the other hand, uses application class loader to initialize log handlers. To resolve this, you can either add `ignite-log4j2` module to the list of the used jars so that Ignite would use Log4j2 as a logging subsystem, or alter default Spark classpath as described link:ignite-for-spark/installation[here]. diff --git a/docs/_docs/installation/installing-using-docker.adoc b/docs/_docs/installation/installing-using-docker.adoc index b0e16509c24ea..b84775c1d674f 100644 --- a/docs/_docs/installation/installing-using-docker.adoc +++ b/docs/_docs/installation/installing-using-docker.adoc @@ -188,7 +188,7 @@ sudo docker run -d \ By default, the Ignite Docker image starts with the following modules enabled: -- ignite-log4j, +- ignite-log4j2, - ignite-spring, - ignite-indexing. @@ -202,7 +202,7 @@ The following parameters can be passed as environment variables in the docker co | `CONFIG_URI` | URL to the Ignite configuration file (can also be relative to the META-INF folder on the class path). The downloaded config file is saved to ./ignite-config.xml | N/A -| `OPTION_LIBS` | A list of link:setup#enabling-modules[modules] that will be enabled for the node. | ignite-log4j, ignite-spring, ignite-indexing +| `OPTION_LIBS` | A list of link:setup#enabling-modules[modules] that will be enabled for the node. | ignite-log4j2, ignite-spring, ignite-indexing | `JVM_OPTS` | JVM arguments passed to the Ignite instance.| N/A diff --git a/docs/_docs/logging.adoc b/docs/_docs/logging.adoc index 48c67b67d2b3d..09282617a48d6 100644 --- a/docs/_docs/logging.adoc +++ b/docs/_docs/logging.adoc @@ -19,7 +19,6 @@ Ignite supports a number of logging libraries and frameworks: - JUL (default), -- Log4j, - Log4j2, - JCL, - SLF4J. @@ -49,40 +48,6 @@ You can override the default logging directory by specifying the `IGNITE_LOG_DIR If you use Ignite as a library in your application, the default logging configuration includes only console handler at INFO level. You can provide a custom configuration file via the `java.util.logging.config.file` system property. -== Using Log4j - -[CAUTION] -==== -[discrete] -The ignite-log4j module is deprecated and will be removed in the next releases. -Log4j 1.x had link:https://blogs.apache.org/foundation/entry/apache_logging_services_project_announces[reached end of life] and contains critical vulnerabilities. -Use link:logging#using-log4j2[ignite-log4j2] module instead. -==== - -NOTE: Before using Log4j, enable the link:setup#enabling-modules[ignite-log4j] module. - -To enable Log4j logger, set the `gridLogger` property of `IgniteConfiguration`, as shown in the following example: - -:javaFile: {javaCodeDir}/Logging.java - -[tabs] --- -tab:XML[] -[source,xml] ----- -include::code-snippets/xml/log4j.xml[tags=log4j;!discovery, indent=0] ----- -tab:Java[] -[source,java] ----- -include::{javaFile}[tag=log4j, indent=0] ----- -tab:.NET[unsupported] -tab:C++[unsupported] --- - -In the above example, the path to `log4j-config.xml` can be either an absolute path, a local path relative to META-INF in classpath or to `IGNITE_HOME`. An example log4j configuration file can be found in the distribution package (`$IGNITE_HOME/config/ignite-log4j.xml`). - == Using Log4j2 NOTE: Before using Log4j2, enable the link:setup#enabling-modules[ignite-log4j2] module. @@ -108,14 +73,14 @@ tab:.NET[unsupported] tab:C++[unsupported] -- -In the above example, the path to `log4j2-config.xml` can be either an absolute path, a local path relative to META-INF in classpath or to `IGNITE_HOME`. An example log4j2 configuration file can be found in the distribution package (`$IGNITE_HOME/config/ignite-log4j2.xml`). +In the above example, the path to `log4j2-config.xml` can be either an absolute path, a local path relative to META-INF in classpath or to `IGNITE_HOME`. An example log4j2 configuration file can be found in the distribution package (`$IGNITE_HOME/config/ignite-log4j.xml`). NOTE: Log4j2 supports runtime reconfiguration, i.e. changes in the configuration file is applied without the need to restart the application. == Using JCL NOTE: Before using JCL, enable the link:setup#enabling-modules[ignite-jcl] module. -NOTE: Note that JCL simply forwards logging messages to an underlying logging system, which needs to be properly configured. Refer to the link:https://commons.apache.org/proper/commons-logging/guide.html#Configuration[JCL official documentation] for more information. For example, if you want to use Log4j, make sure you add the required libraries to your classpath. +NOTE: Note that JCL simply forwards logging messages to an underlying logging system, which needs to be properly configured. Refer to the link:https://commons.apache.org/proper/commons-logging/guide.html#Configuration[JCL official documentation] for more information. For example, if you want to use Log4j2, make sure you add the required libraries to your classpath. To enable Log4j2 logger, set the `gridLogger` property of `IgniteConfiguration`, as shown below: @@ -182,9 +147,9 @@ See link:starting-nodes#setting-jvm-options[Setting JVM Options] to learn about The following steps guide you through the process of configuring logging. This should be suitable for most cases. -. Use either Log4j or Log4j2 as the logging framework. To enable it, follow the instructions provided in the corresponding section above. -. If you use the default configuration file (either `ignite-log4j.xml` or `ignite-log4j2.xml`), uncomment the CONSOLE appender. -. In the log4j configuration file, set the path to the log file. The default location is `${IGNITE_HOME}/work/log/ignite.log`. +. To enable Log4j2, follow the instructions provided in the corresponding section above. +. If you use the default configuration file (`ignite-log4j.xml`), uncomment the CONSOLE appender. +. In the log4j2 configuration file, set the path to the log file. The default location is `${IGNITE_HOME}/work/log/ignite.log`. . Start the nodes in verbose mode: - If you use `ignite.sh` to start nodes, specify the `-v` option. - If you start nodes from Java code, use the `IGNITE_QUIET=false` system variable. diff --git a/docs/_docs/setup.adoc b/docs/_docs/setup.adoc index fcbc2adfb8b42..13e2eb7b16ea8 100644 --- a/docs/_docs/setup.adoc +++ b/docs/_docs/setup.adoc @@ -214,8 +214,6 @@ The following modules are available: |ignite-kubernetes | Ignite Kubernetes module provides a TCP Discovery IP Finder that uses a dedicated Kubernetes service for IP addresses lookup of Ignite pods containerized by Kubernetes. -|ignite-log4j |Support for Log4j - |ignite-log4j2 |Support for Log4j2 diff --git a/examples/pom-standalone-lgpl.xml b/examples/pom-standalone-lgpl.xml index 23ab8d661b593..2499ad5e9e1d6 100644 --- a/examples/pom-standalone-lgpl.xml +++ b/examples/pom-standalone-lgpl.xml @@ -69,7 +69,7 @@ ${project.groupId} - ignite-log4j + ignite-log4j2 to_be_replaced_by_ignite_version diff --git a/examples/pom-standalone.xml b/examples/pom-standalone.xml index 23ab8d661b593..2499ad5e9e1d6 100644 --- a/examples/pom-standalone.xml +++ b/examples/pom-standalone.xml @@ -69,7 +69,7 @@ ${project.groupId} - ignite-log4j + ignite-log4j2 to_be_replaced_by_ignite_version diff --git a/examples/pom.xml b/examples/pom.xml index 5eb93fc3c7c77..488478c512c0c 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -71,7 +71,7 @@ ${project.groupId} - ignite-log4j + ignite-log4j2 diff --git a/modules/calcite/pom.xml b/modules/calcite/pom.xml index acaaee4bb3b21..5527715b47380 100644 --- a/modules/calcite/pom.xml +++ b/modules/calcite/pom.xml @@ -181,15 +181,8 @@ - log4j - log4j - test - - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} + org.apache.logging.log4j + log4j-slf4j-impl test diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/logical/ScriptTestRunner.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/logical/ScriptTestRunner.java index 9f7afdfbe0459..24899ef5489c0 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/logical/ScriptTestRunner.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/logical/ScriptTestRunner.java @@ -61,7 +61,7 @@ public class ScriptTestRunner extends Runner { static { try { - log = new GridTestLog4jLogger(U.resolveIgnitePath("modules/core/src/test/config/log4j-test.xml")); + log = new GridTestLog4jLogger(U.resolveIgnitePath("modules/core/src/test/config/log4j2-test.xml")); } catch (Exception e) { e.printStackTrace(System.err); diff --git a/modules/cassandra/store/pom.xml b/modules/cassandra/store/pom.xml index 0fd18e79de31c..f447ff7daf435 100644 --- a/modules/cassandra/store/pom.xml +++ b/modules/cassandra/store/pom.xml @@ -62,7 +62,7 @@ ${project.groupId} - ignite-log4j + ignite-log4j2 test @@ -150,16 +150,16 @@ - - log4j - log4j + org.mockito + mockito-core test - org.mockito - mockito-core + ${project.groupId} + ignite-core + test-jar test diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraDirectPersistenceLoadTest.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraDirectPersistenceLoadTest.java index c031bfba004cb..48f85c3426e30 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraDirectPersistenceLoadTest.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraDirectPersistenceLoadTest.java @@ -25,7 +25,8 @@ import org.apache.ignite.tests.utils.CacheStoreHelper; import org.apache.ignite.tests.utils.CassandraHelper; import org.apache.ignite.tests.utils.TestsHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Load tests for {@link org.apache.ignite.cache.store.cassandra.CassandraCacheStore} implementation of @@ -33,7 +34,7 @@ */ public class CassandraDirectPersistenceLoadTest extends LoadTestDriver { /** */ - private static final Logger LOGGER = Logger.getLogger("CassandraLoadTests"); + private static final Logger LOGGER = LogManager.getLogger("CassandraLoadTests"); /** * @@ -101,7 +102,7 @@ public static void main(String[] args) { TestsHelper.getLoadTestsCacheName(), TestsHelper.getLoadTestsPersistenceSettings(), CassandraHelper.getAdminDataSrc(), - Logger.getLogger(logName)); + LogManager.getLogger(logName)); } } diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraDirectPersistenceTest.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraDirectPersistenceTest.java index 8a5babb93f309..0bc33677bb400 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraDirectPersistenceTest.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraDirectPersistenceTest.java @@ -35,7 +35,8 @@ import org.apache.ignite.tests.utils.TestTransaction; import org.apache.ignite.tests.utils.TestsHelper; import org.apache.ignite.transactions.Transaction; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -47,7 +48,7 @@ */ public class CassandraDirectPersistenceTest { /** */ - private static final Logger LOGGER = Logger.getLogger(CassandraDirectPersistenceTest.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(CassandraDirectPersistenceTest.class.getName()); /** */ @BeforeClass diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraLocalServer.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraLocalServer.java index eea4e9e114ee5..a229d955e300c 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraLocalServer.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/CassandraLocalServer.java @@ -18,14 +18,15 @@ package org.apache.ignite.tests; import org.apache.ignite.tests.utils.CassandraHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Simple helper class to run Cassandra on localhost */ public class CassandraLocalServer { /** */ - private static final Logger LOGGER = Logger.getLogger(CassandraLocalServer.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(CassandraLocalServer.class.getName()); /** */ public static void main(String[] args) { diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStoreLoadTest.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStoreLoadTest.java index bfcf751c837c0..9a759bc3c0563 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStoreLoadTest.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStoreLoadTest.java @@ -26,7 +26,8 @@ import org.apache.ignite.tests.load.ignite.WriteWorker; import org.apache.ignite.tests.utils.CassandraHelper; import org.apache.ignite.tests.utils.TestsHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Load tests for Ignite caches which utilizing {@link org.apache.ignite.cache.store.cassandra.CassandraCacheStore} @@ -34,7 +35,7 @@ */ public class IgnitePersistentStoreLoadTest extends LoadTestDriver { /** */ - private static final Logger LOGGER = Logger.getLogger("IgniteLoadTests"); + private static final Logger LOGGER = LogManager.getLogger("IgniteLoadTests"); /** * test starter. diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStorePrimitiveTest.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStorePrimitiveTest.java index 5b0e88aea07e4..5b2799a2b59c1 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStorePrimitiveTest.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStorePrimitiveTest.java @@ -31,7 +31,8 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.tests.utils.CassandraAdminCredentials; import org.apache.ignite.tests.utils.CassandraHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -44,7 +45,7 @@ */ public class IgnitePersistentStorePrimitiveTest { /** */ - private static final Logger LOGGER = Logger.getLogger(IgnitePersistentStorePrimitiveTest.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(IgnitePersistentStorePrimitiveTest.class.getName()); /** */ @BeforeClass diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStoreTest.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStoreTest.java index 8678875dddc7d..1aeade57aab11 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStoreTest.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/IgnitePersistentStoreTest.java @@ -52,7 +52,8 @@ import org.apache.ignite.transactions.Transaction; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -65,7 +66,7 @@ */ public class IgnitePersistentStoreTest { /** */ - private static final Logger LOGGER = Logger.getLogger(IgnitePersistentStoreTest.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(IgnitePersistentStoreTest.class.getName()); /** */ @BeforeClass diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/load/LoadTestDriver.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/load/LoadTestDriver.java index bbe9f18a65f5a..a244da1f8bde7 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/load/LoadTestDriver.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/load/LoadTestDriver.java @@ -24,7 +24,7 @@ import org.apache.ignite.cache.store.CacheStore; import org.apache.ignite.cache.store.cassandra.common.SystemHelper; import org.apache.ignite.tests.utils.TestsHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; /** * Basic load test driver to be inherited by specific implementation for particular use-case. diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/load/Worker.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/load/Worker.java index 9a69eb8c91dc2..0aa20c0b2de3a 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/load/Worker.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/load/Worker.java @@ -31,7 +31,8 @@ import org.apache.ignite.internal.processors.cache.CacheEntryImpl; import org.apache.ignite.internal.util.IgniteUtils; import org.apache.ignite.tests.utils.TestsHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Worker thread abstraction to be inherited by specific load test implementation @@ -97,7 +98,7 @@ public abstract class Worker extends Thread { /** */ public Worker(CacheStore cacheStore, long startPosition, long endPosition) { this.cacheStore = cacheStore; - this.log = Logger.getLogger(loggerName()); + this.log = LogManager.getLogger(loggerName()); this.startPosition = startPosition; this.endPosition = endPosition; } @@ -105,7 +106,7 @@ public Worker(CacheStore cacheStore, long startPosition, long endPosition) { /** */ public Worker(Ignite ignite, long startPosition, long endPosition) { this.ignite = ignite; - this.log = Logger.getLogger(loggerName()); + this.log = LogManager.getLogger(loggerName()); this.startPosition = startPosition; this.endPosition = endPosition; } diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/utils/CacheStoreHelper.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/utils/CacheStoreHelper.java index ddfa111c9476f..bf996cdd258a3 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/utils/CacheStoreHelper.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/utils/CacheStoreHelper.java @@ -23,8 +23,9 @@ import org.apache.ignite.cache.store.cassandra.CassandraCacheStore; import org.apache.ignite.cache.store.cassandra.datasource.DataSource; import org.apache.ignite.cache.store.cassandra.persistence.KeyValuePersistenceSettings; -import org.apache.ignite.logger.log4j.Log4JLogger; -import org.apache.log4j.Logger; +import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.core.io.Resource; /** @@ -32,7 +33,7 @@ */ public class CacheStoreHelper { /** */ - private static final Logger LOGGER = Logger.getLogger(CacheStoreHelper.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(CacheStoreHelper.class.getName()); /** */ public static CacheStore createCacheStore(String cacheName, Resource persistenceSettings, DataSource conn) { @@ -66,7 +67,7 @@ public static CacheStore createCacheStore(String cacheName, Resource persistence logField.setAccessible(true); sesField.set(cacheStore, session != null ? session : new TestCacheSession(cacheName)); - logField.set(cacheStore, new Log4JLogger(log)); + logField.set(cacheStore, new GridTestLog4jLogger(log)); } catch (Throwable e) { throw new RuntimeException("Failed to initialize test Ignite cache store", e); diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/utils/CassandraHelper.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/utils/CassandraHelper.java index 8a9934a8b634c..559294a99068f 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/utils/CassandraHelper.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/utils/CassandraHelper.java @@ -34,8 +34,8 @@ import org.apache.ignite.cache.store.cassandra.session.pool.SessionPool; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lifecycle.LifecycleEventType; -import org.apache.ignite.logger.log4j.Log4JLogger; -import org.apache.log4j.Logger; +import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; +import org.apache.logging.log4j.Logger; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -346,7 +346,7 @@ public static void startEmbeddedCassandra(Logger log) { try { Field logField = CassandraLifeCycleBean.class.getDeclaredField("log"); logField.setAccessible(true); - logField.set(embeddedCassandraBean, new Log4JLogger(log)); + logField.set(embeddedCassandraBean, new GridTestLog4jLogger(log)); } catch (Throwable e) { throw new RuntimeException("Failed to initialize logger for CassandraLifeCycleBean", e); diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/testsuites/cassandra/store/IgniteCassandraStoreTestSuite.java b/modules/cassandra/store/src/test/java/org/apache/ignite/testsuites/cassandra/store/IgniteCassandraStoreTestSuite.java index da404570824a3..deeb1291b892f 100644 --- a/modules/cassandra/store/src/test/java/org/apache/ignite/testsuites/cassandra/store/IgniteCassandraStoreTestSuite.java +++ b/modules/cassandra/store/src/test/java/org/apache/ignite/testsuites/cassandra/store/IgniteCassandraStoreTestSuite.java @@ -26,7 +26,8 @@ import org.apache.ignite.tests.IgnitePersistentStoreTest; import org.apache.ignite.tests.utils.CassandraHelper; import org.apache.ignite.tools.junit.JUnitTeamcityReporter; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; @@ -49,7 +50,7 @@ IgnitePersistentStorePrimitiveTest.class}) public class IgniteCassandraStoreTestSuite { /** */ - private static final Logger LOGGER = Logger.getLogger(IgniteCassandraStoreTestSuite.class.getName()); + private static final Logger LOGGER = LogManager.getLogger(IgniteCassandraStoreTestSuite.class.getName()); /** */ @BeforeClass diff --git a/modules/cassandra/store/src/test/resources/log4j.properties b/modules/cassandra/store/src/test/resources/log4j.properties deleted file mode 100644 index 9c67be40e236c..0000000000000 --- a/modules/cassandra/store/src/test/resources/log4j.properties +++ /dev/null @@ -1,119 +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. - -# Root logger option -log4j.rootLogger=INFO, stdout - -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -# ------ LOAD TESTS LOGGING ------ - -# Cassandra load tests loggers -log4j.logger.CassandraLoadTests=INFO, stdout, cassandraLoadTests -log4j.logger.CassandraWriteLoadTest=INFO, csWrite -log4j.logger.CassandraBulkWriteLoadTest=INFO, csBulkWrite -log4j.logger.CassandraReadLoadTest=INFO, csRead -log4j.logger.CassandraBulkReadLoadTest=INFO, csBulkRead - -log4j.appender.cassandraLoadTests=org.apache.log4j.RollingFileAppender -log4j.appender.cassandraLoadTests.File=logs/cassandra-load-tests.log -log4j.appender.cassandraLoadTests.MaxFileSize=10MB -log4j.appender.cassandraLoadTests.MaxBackupIndex=10 -log4j.appender.cassandraLoadTests.Append=true -log4j.appender.cassandraLoadTests.layout=org.apache.log4j.PatternLayout -log4j.appender.cassandraLoadTests.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -log4j.appender.csWrite=org.apache.log4j.RollingFileAppender -log4j.appender.csWrite.File=logs/cassandra-write.log -log4j.appender.csWrite.MaxFileSize=10MB -log4j.appender.csWrite.MaxBackupIndex=10 -log4j.appender.csWrite.Append=true -log4j.appender.csWrite.layout=org.apache.log4j.PatternLayout -log4j.appender.csWrite.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -log4j.appender.csBulkWrite=org.apache.log4j.RollingFileAppender -log4j.appender.csBulkWrite.File=logs/cassandra-bulk-write.log -log4j.appender.csBulkWrite.MaxFileSize=10MB -log4j.appender.csBulkWrite.MaxBackupIndex=10 -log4j.appender.csBulkWrite.Append=true -log4j.appender.csBulkWrite.layout=org.apache.log4j.PatternLayout -log4j.appender.csBulkWrite.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -log4j.appender.csRead=org.apache.log4j.RollingFileAppender -log4j.appender.csRead.File=logs/cassandra-read.log -log4j.appender.csRead.MaxFileSize=10MB -log4j.appender.csRead.MaxBackupIndex=10 -log4j.appender.csRead.Append=true -log4j.appender.csRead.layout=org.apache.log4j.PatternLayout -log4j.appender.csRead.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -log4j.appender.csBulkRead=org.apache.log4j.RollingFileAppender -log4j.appender.csBulkRead.File=logs/cassandra-bulk-read.log -log4j.appender.csBulkRead.MaxFileSize=10MB -log4j.appender.csBulkRead.MaxBackupIndex=10 -log4j.appender.csBulkRead.Append=true -log4j.appender.csBulkRead.layout=org.apache.log4j.PatternLayout -log4j.appender.csBulkRead.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -# Ignite load tests loggers -log4j.logger.IgniteLoadTests=INFO, stdout, igniteLoadTests -log4j.logger.IgniteWriteLoadTest=INFO, igWrite -log4j.logger.IgniteBulkWriteLoadTest=INFO, igBulkWrite -log4j.logger.IgniteReadLoadTest=INFO, igRead -log4j.logger.IgniteBulkReadLoadTest=INFO, igBulkRead - -log4j.appender.igniteLoadTests=org.apache.log4j.RollingFileAppender -log4j.appender.igniteLoadTests.File=logs/ignite-load-tests.log -log4j.appender.igniteLoadTests.MaxFileSize=10MB -log4j.appender.igniteLoadTests.MaxBackupIndex=10 -log4j.appender.igniteLoadTests.Append=true -log4j.appender.igniteLoadTests.layout=org.apache.log4j.PatternLayout -log4j.appender.igniteLoadTests.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -log4j.appender.igWrite=org.apache.log4j.RollingFileAppender -log4j.appender.igWrite.File=logs/ignite-write.log -log4j.appender.igWrite.MaxFileSize=10MB -log4j.appender.igWrite.MaxBackupIndex=10 -log4j.appender.igWrite.Append=true -log4j.appender.igWrite.layout=org.apache.log4j.PatternLayout -log4j.appender.igWrite.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -log4j.appender.igBulkWrite=org.apache.log4j.RollingFileAppender -log4j.appender.igBulkWrite.File=logs/ignite-bulk-write.log -log4j.appender.igBulkWrite.MaxFileSize=10MB -log4j.appender.igBulkWrite.MaxBackupIndex=10 -log4j.appender.igBulkWrite.Append=true -log4j.appender.igBulkWrite.layout=org.apache.log4j.PatternLayout -log4j.appender.igBulkWrite.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -log4j.appender.igRead=org.apache.log4j.RollingFileAppender -log4j.appender.igRead.File=logs/ignite-read.log -log4j.appender.igRead.MaxFileSize=10MB -log4j.appender.igRead.MaxBackupIndex=10 -log4j.appender.igRead.Append=true -log4j.appender.igRead.layout=org.apache.log4j.PatternLayout -log4j.appender.igRead.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n - -log4j.appender.igBulkRead=org.apache.log4j.RollingFileAppender -log4j.appender.igBulkRead.File=logs/ignite-bulk-read.log -log4j.appender.igBulkRead.MaxFileSize=10MB -log4j.appender.igBulkRead.MaxBackupIndex=10 -log4j.appender.igBulkRead.Append=true -log4j.appender.igBulkRead.layout=org.apache.log4j.PatternLayout -log4j.appender.igBulkRead.layout.ConversionPattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n diff --git a/modules/cassandra/store/src/test/resources/log4j2.properties b/modules/cassandra/store/src/test/resources/log4j2.properties new file mode 100644 index 0000000000000..9e79b91ffc1c0 --- /dev/null +++ b/modules/cassandra/store/src/test/resources/log4j2.properties @@ -0,0 +1,178 @@ +# 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. + +rootLogger.level=info +rootLogger.appenderRef.$1.ref=stdout + +# Direct log messages to stdout +appender.stdout.name=stdout +appender.stdout.type=Console +appender.stdout.target=SYSTEM_OUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +# ------ LOAD TESTS LOGGING ------ + +# Cassandra load tests loggers +logger.CassandraLoadTests.name=CassandraLoadTests +logger.CassandraLoadTests.level=INFO +logger.CassandraLoadTests.appenderRef.$1.ref=stdout +logger.CassandraLoadTests.appenderRef.$2.ref=cassandraLoadTests + +logger.CassandraWriteLoadTest.name=CassandraWriteLoadTest +logger.CassandraWriteLoadTest.level=INFO +logger.CassandraWriteLoadTest.appenderRef.$1.ref=csWrite + +logger.CassandraBulkWriteLoadTest.name=CassandraBulkWriteLoadTest +logger.CassandraBulkWriteLoadTest.level=INFO +logger.CassandraBulkWriteLoadTest.appenderRef.$1.ref =csBulkWrite + +logger.CassandraReadLoadTest.name=CassandraReadLoadTest +logger.CassandraReadLoadTest.level=INFO +logger.CassandraReadLoadTest.appenderRef.$1.ref=csRead + +logger.CassandraBulkReadLoadTest.name=CassandraBulkReadLoadTest +logger.CassandraBulkReadLoadTest.level=INFO +logger.CassandraBulkReadLoadTest.appenderRef.$1.ref=csRead + +appender.csWrite.type=RollingFile +appender.csWrite.name=csWrite +appender.csWrite.fileName=logs/cassandra-write.log +appender.csWrite.filePattern=logs/cassandra-write.log%i +appender.csWrite.policies.type=SizeBasedTriggeringPolicy +appender.csWrite.policies.size=10MB +appender.csWrite.strategy.type=DefaultRolloverStrategy +appender.csWrite.strategy.max=10 +appender.csWrite.append=true +appender.csWrite.layout.type=PatternLayout +appender.csWrite.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +appender.csBulkWrite.type=RollingFile +appender.csBulkWrite.name=csBulkWrite +appender.csBulkWrite.fileName=logs/cassandra-bulk-write.log +appender.csBulkWrite.filePattern=logs/cassandra-bulk-write.log%i +appender.csBulkWrite.policies.type=SizeBasedTriggeringPolicy +appender.csBulkWrite.policies.size=10MB +appender.csBulkWrite.strategy.type=DefaultRolloverStrategy +appender.csBulkWrite.strategy.max=10 +appender.csBulkWrite.append=true +appender.csBulkWrite.layout.type=PatternLayout +appender.csBulkWrite.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +appender.csRead.type=RollingFile +appender.csRead.name=csRead +appender.csRead.fileName=logs/cassandra-read.log +appender.csRead.filePattern=logs/cassandra-read.log%i +appender.csRead.policies.type=SizeBasedTriggeringPolicy +appender.csRead.policies.size=10MB +appender.csRead.strategy.type=DefaultRolloverStrategy +appender.csRead.strategy.max=10 +appender.csRead.append=true +appender.csRead.layout.type=PatternLayout +appender.csRead.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +appender.csBulkRead.type=RollingFile +appender.csBulkRead.name=csBulkRead +appender.csBulkRead.fileName=logs/cassandra-bulk-read.log +appender.csBulkRead.filePattern=logs/cassandra-bulk-read.log%i +appender.csBulkRead.policies.type=SizeBasedTriggeringPolicy +appender.csBulkRead.policies.size=10MB +appender.csBulkRead.strategy.type=DefaultRolloverStrategy +appender.csBulkRead.strategy.max=10 +appender.csBulkRead.append=true +appender.csBulkRead.layout.type=PatternLayout +appender.csBulkRead.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +# Ignite load tests loggers +logger.IgniteLoadTests.name=CassandraLoadTests +logger.IgniteLoadTests.level=INFO +logger.IgniteLoadTests.appenderRef.$1.ref=stdout +logger.IgniteLoadTests.appenderRef.$2.ref=igniteLoadTests + +logger.IgniteWriteLoadTest.name=CassandraWriteLoadTest +logger.IgniteWriteLoadTest.level=INFO +logger.IgniteWriteLoadTest.appenderRef.$1.ref=igWrite + +logger.IgniteBulkWriteLoadTest.name=CassandraBulkWriteLoadTest +logger.IgniteBulkWriteLoadTest.level=INFO +logger.IgniteBulkWriteLoadTest.appenderRef.$1.ref=igBulkWrite + +logger.IgniteReadLoadTest.name=CassandraReadLoadTest +logger.IgniteReadLoadTest.level=INFO +logger.IgniteReadLoadTest.appenderRef.$1.ref=igRead + +logger.IgniteBulkReadLoadTest.name=CassandraBulkReadLoadTest +logger.IgniteBulkReadLoadTest.level=INFO +logger.IgniteBulkReadLoadTest.appenderRef.$1.ref=igBulkRead + +appender.igniteLoadTests.type=RollingFile +appender.igniteLoadTests.name=igniteLoadTests +appender.igniteLoadTests.fileName=logs/ignite-load-tests.log +appender.igniteLoadTests.filePattern=logs/ignite-load-tests.log%i +appender.igniteLoadTests.policies.type=SizeBasedTriggeringPolicy +appender.igniteLoadTests.policies.size=10MB +appender.igniteLoadTests.strategy.type=DefaultRolloverStrategy +appender.igniteLoadTests.strategy.max=10 +appender.igniteLoadTests.append=true +appender.igniteLoadTests.layout.type=PatternLayout +appender.igniteLoadTests.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +appender.igWrite.type=RollingFile +appender.igWrite.name=igWrite +appender.igWrite.fileName=logs/ignite-write.log +appender.igWrite.filePattern=logs/ignite-write.log%i +appender.igWrite.policies.type=SizeBasedTriggeringPolicy +appender.igWrite.policies.size=10MB +appender.igWrite.strategy.type=DefaultRolloverStrategy +appender.igWrite.strategy.max=10 +appender.igWrite.append=true +appender.igWrite.layout.type=PatternLayout +appender.igWrite.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +appender.igBulkWrite.type=RollingFile +appender.igBulkWrite.name=igBulkWrite +appender.igBulkWrite.fileName=logs/ignite-bulk-write.log +appender.igBulkWrite.filePattern=logs/ignite-bulk-write.log%i +appender.igBulkWrite.policies.type=SizeBasedTriggeringPolicy +appender.igBulkWrite.policies.size=10MB +appender.igBulkWrite.strategy.type=DefaultRolloverStrategy +appender.igBulkWrite.strategy.max=10 +appender.igBulkWrite.append=true +appender.igBulkWrite.layout.type=PatternLayout +appender.igBulkWrite.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +appender.igRead.type=RollingFile +appender.igRead.name=igRead +appender.igRead.fileName=logs/ignite-read.log +appender.igRead.filePattern=logs/ignite-read.log%i +appender.igRead.policies.type=SizeBasedTriggeringPolicy +appender.igRead.policies.size=10MB +appender.igRead.strategy.type=DefaultRolloverStrategy +appender.igRead.strategy.max=10 +appender.igRead.append=true +appender.igRead.layout.type=PatternLayout +appender.igRead.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n + +appender.igBulkRead.type=RollingFile +appender.igBulkRead.name=igBulkRead +appender.igBulkRead.fileName=logs/ignite-bulk-read.log +appender.igBulkRead.filePattern=logs/ignite-bulk-read.log%i +appender.igBulkRead.policies.type=SizeBasedTriggeringPolicy +appender.igBulkRead.policies.size=10MB +appender.igBulkRead.strategy.type=DefaultRolloverStrategy +appender.igBulkRead.strategy.max=10 +appender.igBulkRead.append=true +appender.igBulkRead.layout.type=PatternLayout +appender.igBulkRead.layout.pattern=%d{HH:mm:ss,SSS} %5p [%t] - %m%n diff --git a/modules/clients/pom.xml b/modules/clients/pom.xml index 6afa2abdb8eba..e3bcd851fa2c4 100644 --- a/modules/clients/pom.xml +++ b/modules/clients/pom.xml @@ -75,7 +75,7 @@ ${project.groupId} - ignite-log4j + ignite-log4j2 test diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java index 789119c58a6be..1992643fbb0f6 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java @@ -104,7 +104,7 @@ public abstract class ClientAbstractSelfTest extends GridCommonAbstractTest { private static final Map cacheStores = new HashMap<>(); /** */ - public static final String ROUTER_LOG_CFG = "modules/core/src/test/config/log4j-test.xml"; + public static final String ROUTER_LOG_CFG = "modules/core/src/test/config/log4j2-test.xml"; /** */ private static final String INTERCEPTED_SUF = "intercepted"; diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterAbstractSelfTest.java index e8701293be71e..3e6de6dd6e3dd 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterAbstractSelfTest.java @@ -28,7 +28,7 @@ import org.apache.ignite.internal.client.integration.ClientAbstractSelfTest; import org.apache.ignite.internal.client.router.impl.GridTcpRouterImpl; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.logger.log4j.Log4JLogger; +import org.apache.ignite.logger.log4j2.Log4J2Logger; import org.junit.Test; /** @@ -110,7 +110,7 @@ public GridTcpRouterConfiguration routerConfiguration() throws IgniteCheckedExce cfg.setPort(ROUTER_PORT); cfg.setPortRange(0); cfg.setServers(Collections.singleton(HOST + ":" + BINARY_PORT)); - cfg.setLogger(new Log4JLogger(ROUTER_LOG_CFG)); + cfg.setLogger(new Log4J2Logger(ROUTER_LOG_CFG)); return cfg; } diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterMultiNodeSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterMultiNodeSelfTest.java index 992d628a78d1f..909e26428fc0a 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterMultiNodeSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/router/TcpRouterMultiNodeSelfTest.java @@ -26,7 +26,7 @@ import org.apache.ignite.internal.client.GridClientProtocol; import org.apache.ignite.internal.client.integration.ClientAbstractMultiNodeSelfTest; import org.apache.ignite.internal.client.router.impl.GridTcpRouterImpl; -import org.apache.ignite.logger.log4j.Log4JLogger; +import org.apache.ignite.logger.log4j2.Log4J2Logger; import static org.apache.ignite.internal.client.integration.ClientAbstractSelfTest.ROUTER_LOG_CFG; @@ -88,7 +88,7 @@ private GridTcpRouterConfiguration routerConfiguration(int i) throws IgniteCheck cfg.setPort(ROUTER_TCP_PORT_BASE + i); cfg.setPortRange(0); cfg.setServers(Collections.singleton(HOST + ":" + REST_TCP_PORT_BASE)); - cfg.setLogger(new Log4JLogger(ROUTER_LOG_CFG)); + cfg.setLogger(new Log4J2Logger(ROUTER_LOG_CFG)); return cfg; } diff --git a/modules/clients/src/test/resources/log4j.xml b/modules/clients/src/test/resources/log4j.xml deleted file mode 100644 index 5c19f0f577df0..0000000000000 --- a/modules/clients/src/test/resources/log4j.xml +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/modules/clients/src/test/resources/log4j2.xml b/modules/clients/src/test/resources/log4j2.xml new file mode 100644 index 0000000000000..6039072022993 --- /dev/null +++ b/modules/clients/src/test/resources/log4j2.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/clients/src/test/resources/spring-router-ssl.xml b/modules/clients/src/test/resources/spring-router-ssl.xml index 6f092f68db58f..e145cce984440 100644 --- a/modules/clients/src/test/resources/spring-router-ssl.xml +++ b/modules/clients/src/test/resources/spring-router-ssl.xml @@ -98,7 +98,7 @@ - - + + diff --git a/modules/clients/src/test/resources/spring-router.xml b/modules/clients/src/test/resources/spring-router.xml index 8e40db9364124..dcc5a16811c15 100644 --- a/modules/clients/src/test/resources/spring-router.xml +++ b/modules/clients/src/test/resources/spring-router.xml @@ -87,7 +87,7 @@ - - + + diff --git a/modules/clients/src/test/resources/spring-server-node.xml b/modules/clients/src/test/resources/spring-server-node.xml index 3211b802a60af..2c27b2f2cdf9b 100644 --- a/modules/clients/src/test/resources/spring-server-node.xml +++ b/modules/clients/src/test/resources/spring-server-node.xml @@ -284,8 +284,8 @@ Logger to use. --> - - + + diff --git a/modules/clients/src/test/resources/spring-server-ssl-node.xml b/modules/clients/src/test/resources/spring-server-ssl-node.xml index d71540d3469a8..d8e16ff230f11 100644 --- a/modules/clients/src/test/resources/spring-server-ssl-node.xml +++ b/modules/clients/src/test/resources/spring-server-ssl-node.xml @@ -270,8 +270,8 @@ Logger to use. --> - - + + diff --git a/modules/compatibility/pom.xml b/modules/compatibility/pom.xml index 3be245abd3220..874bd31fb21fe 100644 --- a/modules/compatibility/pom.xml +++ b/modules/compatibility/pom.xml @@ -92,8 +92,8 @@ - log4j - log4j + org.apache.logging.log4j + log4j-core test diff --git a/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java b/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java index 0c60bd3f3d0b8..46e94db7c2ecd 100644 --- a/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java +++ b/modules/compatibility/src/test/java/org/apache/ignite/compatibility/testframework/junits/IgniteCompatibilityAbstractTest.java @@ -33,12 +33,14 @@ import org.apache.ignite.internal.processors.resource.GridSpringResourceContext; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteInClosure; +import org.apache.ignite.lang.IgniteProductVersion; import org.apache.ignite.testframework.ListeningTestLogger; import org.apache.ignite.testframework.LogListener; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; + import static org.apache.ignite.compatibility.testframework.junits.Dependency.APACHE_IGNITE_GROUP_ID; /** @@ -252,6 +254,9 @@ protected long getNodeJoinTimeout() { dependencies.add(new Dependency("core", "ignite-core", false)); dependencies.add(new Dependency("core", "ignite-core", true)); + if (IgniteProductVersion.fromString("2.14.0").compareTo(IgniteProductVersion.fromString(igniteVer)) > 0) + dependencies.add(new Dependency("log4j", "log4j", "log4j", "1.2.17", false)); + return dependencies; } diff --git a/modules/compress/pom.xml b/modules/compress/pom.xml index 17d17525a39b3..67ac1da1c0d27 100644 --- a/modules/compress/pom.xml +++ b/modules/compress/pom.xml @@ -92,8 +92,8 @@ - log4j - log4j + org.apache.logging.log4j + log4j-core test diff --git a/modules/control-utility/pom.xml b/modules/control-utility/pom.xml index 033e2e7b178c6..42a50502f1087 100644 --- a/modules/control-utility/pom.xml +++ b/modules/control-utility/pom.xml @@ -95,15 +95,8 @@ - org.slf4j - slf4j-log4j12 - ${slf4j.version} - test - - - - log4j - log4j + org.apache.logging.log4j + log4j-slf4j-impl test diff --git a/modules/core/pom.xml b/modules/core/pom.xml index 4d4f28f443a70..455a01d01274b 100644 --- a/modules/core/pom.xml +++ b/modules/core/pom.xml @@ -140,8 +140,8 @@ - log4j - log4j + org.apache.logging.log4j + log4j-core test diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java b/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java index 583e84839d735..c0c0b483ca87b 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java @@ -23,17 +23,17 @@ /** * This interface defines basic logging functionality used throughout the system. We had to * abstract it out so that we can use whatever logging is used by the hosting environment. - * Currently, log4j, + * Currently, log4j2, * JBoss, * JCL and * console logging are provided as supported implementations. *

- * Ignite logger could be configured either from code (for example log4j logger): + * Ignite logger could be configured either from code (for example log4j2 logger): *

  *      IgniteConfiguration cfg = new IgniteConfiguration();
  *      ...
  *      URL xml = U.resolveIgniteUrl("config/custom-log4j.xml");
- *      IgniteLogger log = new Log4JLogger(xml);
+ *      IgniteLogger log = new Log4J2Logger(xml);
  *      ...
  *      cfg.setGridLogger(log);
  * 
@@ -43,7 +43,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.Log4J2Logger"> * <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/> * </bean> * </constructor-arg> diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index bef70315fbd16..07b3c00dfb9ef 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -922,7 +922,7 @@ public IgniteConfiguration setUserAttributes(Map userAttrs) { /** * Should return an instance of logger to use in grid. If not provided, - * {@ignitelink org.apache.ignite.logger.log4j.Log4JLogger} + * {@ignitelink org.apache.ignite.logger.log4j2.Log4J2Logger} * will be used. * * @return Logger to use in grid. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 38636716c228c..6a67355c4b45a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -907,23 +907,7 @@ public static Ignite start(URL springCfgUrl, @Nullable String igniteInstanceName @Nullable GridSpringResourceContext springCtx, @Nullable ClassLoader ldr) throws IgniteCheckedException { A.notNull(springCfgUrl, "springCfgUrl"); - boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null; - - IgniteBiTuple t = null; - - if (isLog4jUsed) { - try { - t = U.addLog4jNoOpLogger(); - } - catch (IgniteCheckedException ignore) { - isLog4jUsed = false; - } - } - - Collection savedHnds = null; - - if (!isLog4jUsed) - savedHnds = U.addJavaNoOpLogger(); + Collection savedHnds = U.addJavaNoOpLogger(); IgniteBiTuple, ? extends GridSpringResourceContext> cfgMap; @@ -931,11 +915,7 @@ public static Ignite start(URL springCfgUrl, @Nullable String igniteInstanceName cfgMap = loadConfigurations(springCfgUrl); } finally { - if (isLog4jUsed && t != null) - U.removeLog4jNoOpLogger(t); - - if (!isLog4jUsed) - U.removeJavaNoOpLogger(savedHnds); + U.removeJavaNoOpLogger(savedHnds); } return startConfigurations(cfgMap, springCfgUrl, igniteInstanceName, springCtx, ldr); @@ -987,23 +967,7 @@ public static Ignite start(InputStream springCfgStream, @Nullable String igniteI @Nullable GridSpringResourceContext springCtx, @Nullable ClassLoader ldr) throws IgniteCheckedException { A.notNull(springCfgStream, "springCfgUrl"); - boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null; - - IgniteBiTuple t = null; - - if (isLog4jUsed) { - try { - t = U.addLog4jNoOpLogger(); - } - catch (IgniteCheckedException ignore) { - isLog4jUsed = false; - } - } - - Collection savedHnds = null; - - if (!isLog4jUsed) - savedHnds = U.addJavaNoOpLogger(); + Collection savedHnds = U.addJavaNoOpLogger(); IgniteBiTuple, ? extends GridSpringResourceContext> cfgMap; @@ -1011,11 +975,7 @@ public static Ignite start(InputStream springCfgStream, @Nullable String igniteI cfgMap = loadConfigurations(springCfgStream); } finally { - if (isLog4jUsed && t != null) - U.removeLog4jNoOpLogger(t); - - if (!isLog4jUsed) - U.removeJavaNoOpLogger(savedHnds); + U.removeJavaNoOpLogger(savedHnds); } return startConfigurations(cfgMap, null, igniteInstanceName, springCtx, ldr); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/GridClientImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/GridClientImpl.java index c52241c0f5bfc..b41b531d822fd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/GridClientImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/GridClientImpl.java @@ -33,7 +33,6 @@ import java.util.logging.Logger; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLException; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteSystemProperties; import org.apache.ignite.internal.client.GridClient; @@ -81,19 +80,8 @@ public class GridClientImpl implements GridClient, GridClientBeforeNodeStart { /* Suppression logging if needed. */ static { - if (!IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_GRID_CLIENT_LOG_ENABLED, false)) { - boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null; - - try { - if (isLog4jUsed) - U.addLog4jNoOpLogger(); - - U.addJavaNoOpLogger(); - } - catch (IgniteCheckedException ignored) { - // If log warning suppression failed, leave it as is. - } - } + if (!IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_GRID_CLIENT_LOG_ENABLED, false)) + log.setLevel(Level.OFF); } /** Client ID. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/router/impl/GridRouterCommandLineStartup.java b/modules/core/src/main/java/org/apache/ignite/internal/client/router/impl/GridRouterCommandLineStartup.java index 52a527944d892..44c46d7d87f25 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/client/router/impl/GridRouterCommandLineStartup.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/client/router/impl/GridRouterCommandLineStartup.java @@ -28,7 +28,6 @@ import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.lang.IgniteBiTuple; import org.apache.ignite.lifecycle.LifecycleAware; import static org.apache.ignite.internal.IgniteComponentType.SPRING; @@ -129,22 +128,7 @@ public static void main(String[] args) throws IgniteCheckedException { System.exit(1); } - boolean isLog4jUsed = U.gridClassLoader().getResource("org/apache/log4j/Appender.class") != null; - - IgniteBiTuple t = null; - Collection savedHnds = null; - - if (isLog4jUsed) { - try { - t = U.addLog4jNoOpLogger(); - } - catch (Exception ignored) { - isLog4jUsed = false; - } - } - - if (!isLog4jUsed) - savedHnds = U.addJavaNoOpLogger(); + Collection savedHnds = U.addJavaNoOpLogger(); Map, Collection> beans; @@ -152,11 +136,7 @@ public static void main(String[] args) throws IgniteCheckedException { beans = spring.loadBeans(cfgUrl, IgniteLogger.class, GridTcpRouterConfiguration.class).get1(); } finally { - if (isLog4jUsed && t != null) - U.removeLog4jNoOpLogger(t); - - if (!isLog4jUsed) - U.removeJavaNoOpLogger(savedHnds); + U.removeJavaNoOpLogger(savedHnds); } final GridRouterCommandLineStartup routerStartup = new GridRouterCommandLineStartup(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 1ff6f1d8065ef..a29516d6e42b6 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -4752,7 +4752,7 @@ public static IgniteLogger initLogger( Class log4jCls; try { - log4jCls = Class.forName("org.apache.ignite.logger.log4j.Log4JLogger"); + log4jCls = Class.forName("org.apache.ignite.logger.log4j2.Log4J2Logger"); } catch (ClassNotFoundException | NoClassDefFoundError ignored) { log4jCls = null; @@ -4813,7 +4813,7 @@ else if (cfgLog instanceof LoggerNodeIdAware) ((LoggerNodeIdAware)cfgLog).setNodeId(nodeId); if (log4jInitErr != null) - U.warn(cfgLog, "Failed to initialize Log4JLogger (falling back to standard java logging): " + U.warn(cfgLog, "Failed to initialize Log4J2Logger (falling back to standard java logging): " + log4jInitErr.getCause()); return cfgLog; @@ -8968,66 +8968,6 @@ public static boolean isVisorRequiredProperty(String name) { "os.name".equals(name) || "os.version".equals(name); } - /** - * Adds no-op logger to remove no-appender warning. - * - * @return Tuple with root log and no-op appender instances. No-op appender can be {@code null} - * if it did not found in classpath. Notice that in this case logging is not suppressed. - * @throws IgniteCheckedException In case of failure to add no-op logger for Log4j. - */ - public static IgniteBiTuple addLog4jNoOpLogger() throws IgniteCheckedException { - Object rootLog; - Object nullApp; - - try { - // Add no-op logger to remove no-appender warning. - Class logCls = Class.forName("org.apache.log4j.Logger"); - - rootLog = logCls.getMethod("getRootLogger").invoke(logCls); - - try { - nullApp = Class.forName("org.apache.log4j.varia.NullAppender").newInstance(); - } - catch (ClassNotFoundException ignore) { - // Can't found log4j no-op appender in classpath (for example, log4j was added through - // log4j-over-slf4j library. No-appender warning will not be suppressed. - return new IgniteBiTuple<>(rootLog, null); - } - - Class appCls = Class.forName("org.apache.log4j.Appender"); - - rootLog.getClass().getMethod("addAppender", appCls).invoke(rootLog, nullApp); - } - catch (Exception e) { - throw new IgniteCheckedException("Failed to add no-op logger for Log4j.", e); - } - - return new IgniteBiTuple<>(rootLog, nullApp); - } - - /** - * Removes previously added no-op logger via method {@link #addLog4jNoOpLogger}. - * - * @param t Tuple with root log and null appender instances. - * @throws IgniteCheckedException In case of failure to remove previously added no-op logger for Log4j. - */ - public static void removeLog4jNoOpLogger(IgniteBiTuple t) throws IgniteCheckedException { - Object rootLog = t.get1(); - Object nullApp = t.get2(); - - if (nullApp == null) - return; - - try { - Class appenderCls = Class.forName("org.apache.log4j.Appender"); - - rootLog.getClass().getMethod("removeAppender", appenderCls).invoke(rootLog, nullApp); - } - catch (Exception e) { - throw new IgniteCheckedException("Failed to remove previously added no-op logger for Log4j.", e); - } - } - /** * Adds no-op console handler for root java logger. * diff --git a/modules/core/src/test/config/log4j-tc-test.xml b/modules/core/src/test/config/log4j-tc-test.xml index 302913e2a6969..ba1d36afaa132 100755 --- a/modules/core/src/test/config/log4j-tc-test.xml +++ b/modules/core/src/test/config/log4j-tc-test.xml @@ -17,105 +17,59 @@ ~ limitations under the License. --> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/core/src/test/config/log4j2-test.xml b/modules/core/src/test/config/log4j2-test.xml index 9740c2ce27e08..e1056be1f5878 100644 --- a/modules/core/src/test/config/log4j2-test.xml +++ b/modules/core/src/test/config/log4j2-test.xml @@ -21,37 +21,70 @@ - + - + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/IgniteTopologyPrintFormatSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/IgniteTopologyPrintFormatSelfTest.java index c131b46cf0e03..a0987d41806a9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/IgniteTopologyPrintFormatSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/IgniteTopologyPrintFormatSelfTest.java @@ -31,7 +31,7 @@ import org.apache.ignite.testframework.LogListener; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; -import org.apache.log4j.Level; +import org.apache.logging.log4j.Level; import org.junit.Test; /** diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheColocatedTxSingleThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheColocatedTxSingleThreadedSelfTest.java index afb85dbb66dd7..0d7fa1cec6d93 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheColocatedTxSingleThreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridCacheColocatedTxSingleThreadedSelfTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.IgniteTxSingleThreadedAbstractTest; -import org.apache.log4j.Level; +import org.apache.logging.log4j.Level; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; import static org.apache.ignite.cache.CacheMode.PARTITIONED; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java index d5f7d92a80ce5..be25f5c110472 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedLockSelfTest.java @@ -21,7 +21,7 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.distributed.GridCacheLockAbstractTest; -import org.apache.log4j.Level; +import org.apache.logging.log4j.Level; import static org.apache.ignite.cache.CacheMode.PARTITIONED; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxMultiThreadedSelfTest.java index d38a1f683802a..a3b5148206174 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxMultiThreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxMultiThreadedSelfTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.configuration.NearCacheConfiguration; import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.IgniteTxMultiThreadedAbstractTest; -import org.apache.log4j.Level; +import org.apache.logging.log4j.Level; import static org.apache.ignite.cache.CacheMode.PARTITIONED; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSingleThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSingleThreadedSelfTest.java index f8fe92727a9f4..570e23499b647 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSingleThreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/GridCachePartitionedTxSingleThreadedSelfTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.IgniteTxSingleThreadedAbstractTest; -import org.apache.log4j.Level; +import org.apache.logging.log4j.Level; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; import static org.apache.ignite.cache.CacheMode.PARTITIONED; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxMultiThreadedSelfTest.java index e44d92f935c30..00b2f7ef62073 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxMultiThreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxMultiThreadedSelfTest.java @@ -22,8 +22,8 @@ import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.IgniteTxMultiThreadedAbstractTest; import org.apache.ignite.testframework.MvccFeatureChecker; -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.Before; import static org.apache.ignite.cache.CacheMode.LOCAL; @@ -58,9 +58,7 @@ public void beforeGridCacheLocalEvictionEventSelfTest() { c.setCacheConfiguration(cc); // Disable log4j debug by default. - Logger log4j = Logger.getLogger(GridCacheProcessor.class.getPackage().getName()); - - log4j.setLevel(CACHE_DEBUG ? Level.DEBUG : Level.INFO); + Configurator.setLevel(GridCacheProcessor.class.getPackage().getName(), CACHE_DEBUG ? Level.DEBUG : Level.INFO); return c; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxSingleThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxSingleThreadedSelfTest.java index 677dd8d15bb51..14aeacfb2b77a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxSingleThreadedSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/local/GridCacheLocalTxSingleThreadedSelfTest.java @@ -22,8 +22,8 @@ import org.apache.ignite.internal.processors.cache.GridCacheProcessor; import org.apache.ignite.internal.processors.cache.IgniteTxSingleThreadedAbstractTest; import org.apache.ignite.testframework.MvccFeatureChecker; -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.Before; import static org.apache.ignite.cache.CacheMode.LOCAL; @@ -58,9 +58,7 @@ public void beforeGridCacheLocalTxSingleThreadedSelfTest() { c.setCacheConfiguration(cc); // Disable log4j debug by default. - Logger log4j = Logger.getLogger(GridCacheProcessor.class.getPackage().getName()); - - log4j.setLevel(CACHE_DEBUG ? Level.DEBUG : Level.INFO); + Configurator.setLevel(GridCacheProcessor.class.getPackage().getName(), CACHE_DEBUG ? Level.DEBUG : Level.INFO); return c; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotMXBeanTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotMXBeanTest.java index fd68a57b5f842..ef44ce14e4108 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotMXBeanTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotMXBeanTest.java @@ -38,6 +38,7 @@ import static org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotRestoreProcess.SNAPSHOT_RESTORE_METRICS; import static org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE; import static org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause; +import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; /** * Tests {@link SnapshotMXBean}. @@ -153,9 +154,12 @@ public void testCancelRestoreSnapshot() throws Exception { assertThrowsAnyCause(log, () -> fut.get(TIMEOUT), IgniteCheckedException.class, expErrMsg); assertTrue((long)getMetric("endTime", mReg0) > 0); - assertTrue((long)getMetric("endTime", mReg1) > 0); assertTrue(((String)getMetric("error", mReg0)).contains(expErrMsg)); - assertTrue(((String)getMetric("error", mReg1)).contains(expErrMsg)); + + // We use {@code waitForCondition} here and below since {@code fut} completeness guarantees that snapshot + // procedure is completed only on the initiator node. Remote nodes can not handle snapshot cancellation event yet. + assertTrue(waitForCondition(() -> (long)getMetric("endTime", mReg1) > 0, getTestTimeout())); + assertTrue(waitForCondition(() -> ((String)getMetric("error", mReg1)).contains(expErrMsg), getTestTimeout())); assertNull(ignite.cache(DEFAULT_CACHE_NAME)); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImplSelfTest.java index 66e27f07f06ed..e4d4cf9fe90e0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImplSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImplSelfTest.java @@ -52,15 +52,15 @@ import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.apache.log4j.Appender; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; -import org.apache.log4j.WriterAppender; +import org.apache.logging.log4j.core.appender.WriterAppender; import org.junit.Ignore; import org.junit.Test; import static org.apache.ignite.cache.CacheMode.PARTITIONED; import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.addRootLoggerAppender; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.removeRootLoggerAppender; +import static org.apache.logging.log4j.Level.ALL; /** * Tests for {@code IgniteDataStreamerImpl}. @@ -437,9 +437,12 @@ public void testRetryWhenTopologyMismatch() throws Exception { cnt = 0; StringWriter logWriter = new StringWriter(); - Appender logAppender = new WriterAppender(new SimpleLayout(), logWriter); + String appName = "test-string-writer"; - Logger.getRootLogger().addAppender(logAppender); + addRootLoggerAppender(ALL, WriterAppender.newBuilder() + .setName(appName) + .setTarget(logWriter) + .build()); startGrids(MAX_CACHE_COUNT - 1); // cache-enabled nodes @@ -455,9 +458,7 @@ public void testRetryWhenTopologyMismatch() throws Exception { logWriter.flush(); - Logger.getRootLogger().removeAppender(logAppender); - - logAppender.close(); + removeRootLoggerAppender(appName); } assertFalse(logWriter.toString().contains("DataStreamer will retry data transfer at stable topology")); diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/GridSingleExecutionTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/GridSingleExecutionTest.java index d2ac5f6507a09..495b367af46f9 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/GridSingleExecutionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/GridSingleExecutionTest.java @@ -18,7 +18,6 @@ package org.apache.ignite.loadtests; import java.io.File; -import java.io.IOException; import java.io.Serializable; import java.net.MalformedURLException; import java.util.ArrayList; @@ -45,18 +44,29 @@ import org.apache.ignite.resources.TaskSessionResource; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; -import org.apache.log4j.Appender; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.RollingFileAppender; -import org.apache.log4j.varia.LevelRangeFilter; -import org.apache.log4j.varia.NullAppender; +import org.apache.logging.log4j.core.appender.ConsoleAppender; +import org.apache.logging.log4j.core.appender.RollingFileAppender; +import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.core.filter.LevelRangeFilter; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.CONSOLE; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.CONSOLE_ERROR; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.DEFAULT_PATTERN_LAYOUT; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.FILE; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.addRootLoggerAppender; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.removeAllRootLoggerAppenders; +import static org.apache.logging.log4j.Level.DEBUG; +import static org.apache.logging.log4j.Level.INFO; +import static org.apache.logging.log4j.Level.WARN; +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; + /** * Single execution test. */ @@ -130,59 +140,37 @@ else if (args.length >= 2) { * @throws IgniteCheckedException If file initialization failed. */ private static IgniteLogger initLogger(String log) throws IgniteCheckedException { - - Logger impl = Logger.getRootLogger(); - - impl.removeAllAppenders(); + removeAllRootLoggerAppenders(); String fileName = U.getIgniteHome() + "/work/log/" + log; - // Configure output that should go to System.out - RollingFileAppender fileApp; - - String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"; - - try { - fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName); - - fileApp.setMaxBackupIndex(0); - - fileApp.rollOver(); - } - catch (IOException e) { - throw new IgniteCheckedException("Unable to initialize file appender.", e); - } - - LevelRangeFilter lvlFilter = new LevelRangeFilter(); - - lvlFilter.setLevelMin(Level.DEBUG); - - fileApp.addFilter(lvlFilter); - - impl.addAppender(fileApp); + // Configure output that should go to file + addRootLoggerAppender(DEBUG, RollingFileAppender.newBuilder() + .setName(FILE) + .withFileName(fileName) + .withFilePattern(fileName + ".%i") + .setLayout(DEFAULT_PATTERN_LAYOUT) + .withStrategy(DefaultRolloverStrategy.newBuilder().withMax("0").build()) + .build()); // Configure output that should go to System.out - ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT); - - lvlFilter = new LevelRangeFilter(); - - lvlFilter.setLevelMin(Level.INFO); - lvlFilter.setLevelMax(Level.INFO); - - conApp.addFilter(lvlFilter); - - impl.addAppender(conApp); + addRootLoggerAppender(INFO, ConsoleAppender.newBuilder() + .setName(CONSOLE) + .setTarget(SYSTEM_OUT) + .setFilter(LevelRangeFilter.createFilter(INFO, INFO, ACCEPT, DENY)) + .setLayout(DEFAULT_PATTERN_LAYOUT) + .build()); // Configure output that should go to System.err - conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR); - - conApp.setThreshold(Level.WARN); - - impl.addAppender(conApp); + addRootLoggerAppender(WARN, ConsoleAppender.newBuilder() + .setName(CONSOLE_ERROR) + .setTarget(SYSTEM_ERR) + .setLayout(DEFAULT_PATTERN_LAYOUT) + .build()); - impl.setLevel(Level.INFO); + Configurator.setRootLevel(INFO); - Logger.getLogger("org.apache.ignite").setLevel(Level.DEBUG); + Configurator.setLevel("org.apache.ignite", DEBUG); return new GridTestLog4jLogger(false); } @@ -206,11 +194,6 @@ private static Iterable getConfigurations(String springCfgP if (!path.isFile()) throw new IgniteCheckedException("Provided file path is not a file: " + path); - // Add no-op logger to remove no-appender warning. - Appender app = new NullAppender(); - - Logger.getRootLogger().addAppender(app); - ApplicationContext springCtx; try { @@ -234,9 +217,6 @@ private static Iterable getConfigurations(String springCfgP if (cfgMap == null) throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); - // Remove previously added no-op logger. - Logger.getRootLogger().removeAppender(app); - if (cfgMap.isEmpty()) throw new IgniteCheckedException("Can't find grid factory configuration in: " + path); diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheAbstractLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheAbstractLoadTest.java index 37c0cf4bbf1d7..2cf3e737b7757 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheAbstractLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheAbstractLoadTest.java @@ -41,19 +41,29 @@ import org.apache.ignite.transactions.Transaction; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; -import org.apache.log4j.Appender; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.RollingFileAppender; -import org.apache.log4j.varia.LevelRangeFilter; -import org.apache.log4j.varia.NullAppender; +import org.apache.logging.log4j.core.appender.ConsoleAppender; +import org.apache.logging.log4j.core.appender.RollingFileAppender; +import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.core.filter.LevelRangeFilter; import org.jetbrains.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.CONSOLE; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.CONSOLE_ERROR; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.DEFAULT_PATTERN_LAYOUT; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.FILE; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.addRootLoggerAppender; +import static org.apache.logging.log4j.Level.DEBUG; +import static org.apache.logging.log4j.Level.INFO; +import static org.apache.logging.log4j.Level.WARN; +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; + /** * Common stuff for cache load tests. */ @@ -261,66 +271,39 @@ protected static void error(String msg) { * @throws IgniteCheckedException If file initialization failed. */ protected IgniteLogger initLogger(String log) throws IgniteCheckedException { - Logger impl = Logger.getRootLogger(); - - impl.removeAllAppenders(); + GridTestLog4jLogger.removeAllRootLoggerAppenders(); String fileName = U.getIgniteHome() + "/work/log/" + log; - // Configure output that should go to System.out - RollingFileAppender fileApp; - - String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"; - - try { - fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName); - - fileApp.setMaxBackupIndex(0); - fileApp.setAppend(false); - - // fileApp.rollOver(); - - fileApp.activateOptions(); - } - catch (IOException e) { - throw new IgniteCheckedException("Unable to initialize file appender.", e); - } - - LevelRangeFilter lvlFilter = new LevelRangeFilter(); - - lvlFilter.setLevelMin(Level.DEBUG); - - fileApp.addFilter(lvlFilter); - - impl.addAppender(fileApp); + // Configure output that should go to file + addRootLoggerAppender(DEBUG, RollingFileAppender.newBuilder() + .setName(FILE) + .withFileName(fileName) + .withFilePattern(fileName + ".%i") + .setLayout(DEFAULT_PATTERN_LAYOUT) + .withStrategy(DefaultRolloverStrategy.newBuilder().withMax("0").build()) + .withAppend(false) + .build()); // Configure output that should go to System.out - ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT); - - lvlFilter = new LevelRangeFilter(); - - lvlFilter.setLevelMin(Level.DEBUG); - lvlFilter.setLevelMax(Level.INFO); - - conApp.addFilter(lvlFilter); - - conApp.activateOptions(); - - impl.addAppender(conApp); + addRootLoggerAppender(DEBUG, ConsoleAppender.newBuilder() + .setName(CONSOLE) + .setTarget(SYSTEM_OUT) + .setFilter(LevelRangeFilter.createFilter(INFO, DEBUG, ACCEPT, DENY)) + .setLayout(DEFAULT_PATTERN_LAYOUT) + .build()); // Configure output that should go to System.err - conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR); + addRootLoggerAppender(WARN, ConsoleAppender.newBuilder() + .setName(CONSOLE_ERROR) + .setTarget(SYSTEM_ERR) + .setLayout(DEFAULT_PATTERN_LAYOUT) + .build()); - conApp.setThreshold(Level.WARN); + Configurator.setRootLevel(INFO); - conApp.activateOptions(); - - impl.addAppender(conApp); - - impl.setLevel(Level.INFO); - - //Logger.getLogger("org.apache.ignite").setLevel(Level.INFO); - //Logger.getLogger(GridCacheVersionManager.class).setLevel(Level.DEBUG); +// Configurator.setLevel("org.apache.ignite", INFO); +// Configurator.setLevel(GridCacheVersionManager.class, DEBUG); return new GridTestLog4jLogger(false); } @@ -343,11 +326,6 @@ protected IgniteConfiguration configuration(String springCfgPath, String log) th if (!path.isFile()) throw new IgniteCheckedException("Provided file path is not a file: " + path); - // Add no-op logger to remove no-appender warning. - Appender app = new NullAppender(); - - Logger.getRootLogger().addAppender(app); - ApplicationContext springCtx; try { @@ -371,9 +349,6 @@ protected IgniteConfiguration configuration(String springCfgPath, String log) th if (cfgMap == null) throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); - // Remove previously added no-op logger. - Logger.getRootLogger().removeAppender(app); - if (cfgMap.isEmpty()) throw new IgniteCheckedException("Can't find grid factory configuration in: " + path); else if (cfgMap.size() > 1) diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiInverseConnectionLoggingTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiInverseConnectionLoggingTest.java index 4893b4c3e3c88..401d2a1302f90 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiInverseConnectionLoggingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiInverseConnectionLoggingTest.java @@ -38,8 +38,8 @@ import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.MemorizingAppender; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.apache.log4j.Level; -import org.apache.log4j.spi.LoggingEvent; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.LogEvent; import org.junit.Test; import static java.util.Collections.singletonList; @@ -114,8 +114,8 @@ public void logsWarnForExceptionMeaningSwitchToInverseConnection() throws Except sendFailingMessage(server, clientNode); - LoggingEvent event = log4jAppender.singleEventSatisfying( - evt -> evt.getRenderedMessage().startsWith("Failed to send message to remote node ") + LogEvent event = log4jAppender.singleEventSatisfying( + evt -> evt.getMessage().getFormattedMessage().startsWith("Failed to send message to remote node ") ); assertThat(event.getLevel(), is(Level.WARN)); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiNodeLeftLoggingTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiNodeLeftLoggingTest.java index 4d30caa773159..8196d6c44320f 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiNodeLeftLoggingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiNodeLeftLoggingTest.java @@ -26,8 +26,8 @@ import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.MemorizingAppender; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.apache.log4j.Level; -import org.apache.log4j.spi.LoggingEvent; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.LogEvent; import org.junit.Test; import static java.util.Collections.singletonList; @@ -93,8 +93,8 @@ public void logsWithErrorWhenCantSendMessageToServerWhichLeft() throws Exception sendFailingMessage(server1, server2Node); - LoggingEvent event = log4jAppender.singleEventSatisfying( - evt -> evt.getRenderedMessage().startsWith("Failed to send message to remote node") + LogEvent event = log4jAppender.singleEventSatisfying( + evt -> evt.getMessage().getFormattedMessage().startsWith("Failed to send message to remote node") ); assertThat(event.getLevel(), is(Level.ERROR)); @@ -143,8 +143,8 @@ public void logsWithWarnWhenCantSendMessageToClientWhichLeft() throws Exception sendFailingMessage(server, clientNode); - LoggingEvent event = log4jAppender.singleEventSatisfying( - evt -> evt.getRenderedMessage().startsWith("Failed to send message to remote node") + LogEvent event = log4jAppender.singleEventSatisfying( + evt -> evt.getMessage().getFormattedMessage().startsWith("Failed to send message to remote node") ); assertThat(event.getLevel(), is(Level.WARN)); diff --git a/modules/core/src/test/java/org/apache/ignite/startup/GridRandomCommandLineLoader.java b/modules/core/src/test/java/org/apache/ignite/startup/GridRandomCommandLineLoader.java index 1e0fc9b8dd9a8..468102c43c855 100644 --- a/modules/core/src/test/java/org/apache/ignite/startup/GridRandomCommandLineLoader.java +++ b/modules/core/src/test/java/org/apache/ignite/startup/GridRandomCommandLineLoader.java @@ -41,9 +41,6 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; -import org.apache.log4j.Appender; -import org.apache.log4j.Logger; -import org.apache.log4j.varia.NullAppender; import org.jetbrains.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; @@ -313,11 +310,6 @@ private static IgniteConfiguration getConfiguration(String springCfgPath, @Nulla if (!path.isFile()) throw new IgniteCheckedException("Provided file path is not a file: " + path); - // Add no-op logger to remove no-appender warning. - Appender app = new NullAppender(); - - Logger.getRootLogger().addAppender(app); - ApplicationContext springCtx; try { @@ -341,9 +333,6 @@ private static IgniteConfiguration getConfiguration(String springCfgPath, @Nulla if (cfgMap == null) throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); - // Remove previously added no-op logger. - Logger.getRootLogger().removeAppender(app); - if (cfgMap.size() != 1) throw new IgniteCheckedException("Spring configuration file should contain exactly 1 grid configuration: " + path); diff --git a/modules/core/src/test/java/org/apache/ignite/startup/GridVmNodesStarter.java b/modules/core/src/test/java/org/apache/ignite/startup/GridVmNodesStarter.java index 8aeff690c96a0..a8de945b228ad 100644 --- a/modules/core/src/test/java/org/apache/ignite/startup/GridVmNodesStarter.java +++ b/modules/core/src/test/java/org/apache/ignite/startup/GridVmNodesStarter.java @@ -36,9 +36,6 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.testframework.GridTestUtils; -import org.apache.log4j.Appender; -import org.apache.log4j.Logger; -import org.apache.log4j.varia.NullAppender; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; @@ -203,11 +200,6 @@ private static Iterable getConfigurations(String springCfgP if (!path.isFile()) throw new IgniteCheckedException("Provided file path is not a file: " + path); - // Add no-op logger to remove no-appender warning. - Appender app = new NullAppender(); - - Logger.getRootLogger().addAppender(app); - ApplicationContext springCtx; try { @@ -231,9 +223,6 @@ private static Iterable getConfigurations(String springCfgP if (cfgMap == null) throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); - // Remove previously added no-op logger. - Logger.getRootLogger().removeAppender(app); - if (cfgMap.isEmpty()) throw new IgniteCheckedException("Can't find grid factory configuration in: " + path); diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/MemorizingAppender.java b/modules/core/src/test/java/org/apache/ignite/testframework/MemorizingAppender.java index a1d78c19328e7..e9fd677f42133 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/MemorizingAppender.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/MemorizingAppender.java @@ -21,37 +21,35 @@ import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Predicate; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.Logger; -import org.apache.log4j.spi.LoggingEvent; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.LoggerConfig; +import org.apache.logging.log4j.core.config.Property; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; /** - * A Log4j {@link org.apache.log4j.Appender} that memorizes all the events it gets from loggers. These events are made - * available to the class users. + * A Log4j2 {@link org.apache.logging.log4j.core.appender.AbstractAppender} that memorizes all the events it gets from loggers. + * These events are made available to the class users. */ -public class MemorizingAppender extends AppenderSkeleton { +public class MemorizingAppender extends AbstractAppender { /** * Events that were seen by this Appender. */ - private final List events = new CopyOnWriteArrayList<>(); + private final List events = new CopyOnWriteArrayList<>(); /** {@inheritDoc} */ - @Override protected void append(LoggingEvent event) { + @Override public void append(LogEvent event) { events.add(event); } - /** {@inheritDoc} */ - @Override public void close() { - // no-op - } - - /** {@inheritDoc} */ - @Override public boolean requiresLayout() { - return false; + /** */ + public MemorizingAppender() { + super(MemorizingAppender.class.getName(), null, null, true, Property.EMPTY_ARRAY); } /** @@ -59,7 +57,7 @@ public class MemorizingAppender extends AppenderSkeleton { * * @return All events that were seen by this Appender so far. */ - public List events() { + public List events() { return new ArrayList<>(events); } @@ -69,9 +67,21 @@ public List events() { * @param target Class on whose logger to install this Appender. */ public void installSelfOn(Class target) { - Logger logger = Logger.getLogger(target); + LoggerContext ctx = LoggerContext.getContext(false); + + Configuration cfg = ctx.getConfiguration(); - logger.addAppender(this); + LoggerConfig logCfg = cfg.getLoggers().get(target.getName()); + + if (logCfg == null) { + logCfg = new LoggerConfig(target.getName(), cfg.getLoggerConfig(target.getName()).getLevel(), true); + + cfg.addLogger(target.getName(), logCfg); + } + + logCfg.addAppender(this, null, null); + + ctx.updateLoggers(); } /** @@ -80,9 +90,11 @@ public void installSelfOn(Class target) { * @param target Class from whose logger to remove this Appender. */ public void removeSelfFrom(Class target) { - Logger logger = Logger.getLogger(target); + LoggerConfig logCfg = LoggerContext.getContext(false).getConfiguration().getLoggerConfig(target.getName()); + + logCfg.removeAppender(getName()); - logger.removeAppender(this); + LoggerContext.getContext(false).updateLoggers(); } /** @@ -92,8 +104,8 @@ public void removeSelfFrom(Class target) { * @param predicate Predicate to use to select the event. * @return The single event satisfying the given predicate. */ - public LoggingEvent singleEventSatisfying(Predicate predicate) { - List matches = events.stream().filter(predicate).collect(toList()); + public LogEvent singleEventSatisfying(Predicate predicate) { + List matches = events.stream().filter(predicate).collect(toList()); assertThat(matches, hasSize(1)); diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/MemorizingAppenderTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/MemorizingAppenderTest.java index c32e1232d0677..e8bbdb46a4841 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/MemorizingAppenderTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/MemorizingAppenderTest.java @@ -18,13 +18,16 @@ package org.apache.ignite.testframework; import java.util.List; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.spi.LoggingEvent; +import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.config.Configurator; import org.junit.After; import org.junit.Before; import org.junit.Test; +import static org.apache.logging.log4j.Level.DEBUG; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -38,6 +41,12 @@ public class MemorizingAppenderTest { */ private final MemorizingAppender appender = new MemorizingAppender(); + static { + GridTestLog4jLogger.removeAllRootLoggerAppenders(); + + Configurator.setRootLevel(DEBUG); + } + /***/ @Before public void installAppender() { @@ -55,15 +64,15 @@ public void removeAppender() { */ @Test public void memorizesLoggingEvents() { - Logger.getLogger(MemorizingAppenderTest.class).info("Hello!"); + LogManager.getLogger(MemorizingAppenderTest.class).info("Hello!"); - List events = appender.events(); + List events = appender.events(); assertThat(events, hasSize(1)); - LoggingEvent event = events.get(0); + LogEvent event = events.get(0); assertThat(event.getLevel(), is(Level.INFO)); - assertThat(event.getRenderedMessage(), is("Hello!")); + assertThat(event.getMessage().getFormattedMessage(), is("Hello!")); } } diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java b/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java index 2cd087bfc9261..edadc65e0774d 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/config/GridTestProperties.java @@ -32,7 +32,8 @@ import org.apache.ignite.binary.BinaryTypeConfiguration; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.testframework.GridTestUtils; -import org.apache.log4j.xml.DOMConfigurator; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.core.config.LoggerConfig; import org.jetbrains.annotations.Nullable; /** @@ -127,16 +128,16 @@ private static void configureLog4j(String user) { String cfgFile = System.getProperty("IGNITE_TEST_PROP_LOG4J_FILE"); if (cfgFile == null) - cfgFile = "log4j-test.xml"; + cfgFile = "log4j2-test.xml"; File log4jFile = getTestConfigurationFile(user, cfgFile); if (log4jFile == null) log4jFile = getTestConfigurationFile(null, cfgFile); - DOMConfigurator.configure(log4jFile.getAbsolutePath()); + Configurator.initialize(LoggerConfig.ROOT, log4jFile.getAbsolutePath()); - System.out.println("Configured log4j from: " + log4jFile); + System.out.println("Configured log4j2 from: " + log4jFile); } /** */ diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java index 70144a12f4148..cf53ea150e293 100755 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java @@ -126,13 +126,14 @@ import org.apache.ignite.testframework.junits.multijvm.IgniteNodeRunner; import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy; import org.apache.ignite.thread.IgniteThread; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.Priority; -import org.apache.log4j.RollingFileAppender; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.ConsoleAppender; +import org.apache.logging.log4j.core.appender.RollingFileAppender; +import org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy; +import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.core.config.LoggerConfig; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.After; @@ -171,6 +172,13 @@ import static org.apache.ignite.testframework.GridTestUtils.setFieldValue; import static org.apache.ignite.testframework.config.GridTestProperties.BINARY_MARSHALLER_USE_SIMPLE_NAME_MAPPER; import static org.apache.ignite.testframework.config.GridTestProperties.IGNITE_CFG_PREPROCESSOR_CLS; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.CONSOLE_ERROR; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.DEFAULT_PATTERN_LAYOUT; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.FILE; +import static org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger.addRootLoggerAppender; +import static org.apache.logging.log4j.Level.DEBUG; +import static org.apache.logging.log4j.Level.WARN; +import static org.apache.logging.log4j.core.appender.ConsoleAppender.Target.SYSTEM_ERR; /** * Common abstract test for Ignite tests. @@ -202,7 +210,7 @@ public abstract class GridAbstractTest extends JUnitAssertAware { private static final Map, IgniteTestResources> tests = new ConcurrentHashMap<>(); /** Loggers with changed log level for test's purposes. */ - private static final Map changedLevels = new ConcurrentHashMap<>(); + private static final Map changedLevels = new ConcurrentHashMap<>(); /** */ private static final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean(); @@ -345,8 +353,7 @@ protected void beforeTest() throws Exception { */ protected void afterTest() throws Exception { try { - for (Map.Entry 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