You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/19 23:05:13 UTC

[logging-log4j2] branch release-2.x updated (43a9868 -> 38c60ce)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.


    from 43a9868  Double test timeout to try to make the GitHub builds more resilient.
     new 83b3468  Add ConfigurationSource.ConfigurationSource(InputStream, Path).
     new 93c4783  Add ConfigurationSource.ConfigurationSource(InputStream, Path).
     new 38c60ce  Use NIO in test helper.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/log4j/config/TestConfigurator.java  |  8 ++--
 .../log4j/core/config/ConfigurationSource.java     | 22 ++++++++++
 .../log4j/core/config/TestConfigurator.java        | 49 +++++++++++++++++-----
 3 files changed, 64 insertions(+), 15 deletions(-)

[logging-log4j2] 02/03: Add ConfigurationSource.ConfigurationSource(InputStream, Path).

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 93c478374ba5a42288ba9176862ff68713bfce47
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 19 18:02:42 2022 -0500

    Add ConfigurationSource.ConfigurationSource(InputStream, Path).
---
 .../log4j/core/config/TestConfigurator.java        | 49 +++++++++++++++++-----
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
index 5963f81..b782c67 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
@@ -16,10 +16,29 @@
  */
 package org.apache.logging.log4j.core.config;
 
+import static org.apache.logging.log4j.hamcrest.MapMatchers.hasSize;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.theInstance;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
@@ -43,17 +62,6 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 
-import static org.apache.logging.log4j.hamcrest.MapMatchers.hasSize;
-import static org.hamcrest.MatcherAssert.*;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.hamcrest.Matchers.hasKey;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.theInstance;
-import static org.junit.jupiter.api.Assertions.*;
-
 @Tag("functional")
 public class TestConfigurator {
 
@@ -141,6 +149,25 @@ public class TestConfigurator {
     }
 
     @Test
+    public void testInitialize_InputStream_Path() throws Exception {
+        final Path path = Paths.get("target/test-classes/log4j2-config.xml");
+        final InputStream is = Files.newInputStream(path);
+        final ConfigurationSource source = new ConfigurationSource(is, path);
+        ctx = Configurator.initialize(null, source);
+        LogManager.getLogger("org.apache.test.TestConfigurator");
+        Configuration config = ctx.getConfiguration();
+        assertNotNull(config, "No configuration");
+        assertEquals(CONFIG_NAME, config.getName(), "Incorrect Configuration.");
+        final Map<String, Appender> map = config.getAppenders();
+        assertNotNull(map, "Appenders map should not be null.");
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
+        Configurator.shutdown(ctx);
+        config = ctx.getConfiguration();
+        assertEquals(NullConfiguration.NULL_NAME, config.getName(), "Unexpected Configuration.");
+    }
+
+    @Test
     public void testInitialize_NullClassLoader_ConfigurationSourceWithInputStream_NoId() throws Exception {
         final InputStream is = new FileInputStream("target/test-classes/log4j2-config.xml");
         final ConfigurationSource source =

[logging-log4j2] 03/03: Use NIO in test helper.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 38c60cea3dce210fb28a92b49eac8c4e7ee4bd79
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 19 18:05:08 2022 -0500

    Use NIO in test helper.
---
 .../src/test/java/org/apache/log4j/config/TestConfigurator.java   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/TestConfigurator.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/TestConfigurator.java
index 545f5e0..c98a008 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/TestConfigurator.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/TestConfigurator.java
@@ -19,10 +19,10 @@ package org.apache.log4j.config;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.jupiter.api.Assertions.fail;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 
 import org.apache.log4j.xml.XmlConfigurationFactory;
@@ -34,9 +34,9 @@ import org.apache.logging.log4j.core.config.Configurator;
 public class TestConfigurator {
 
     static LoggerContext configure(final String configLocation) throws IOException {
-        final File file = new File(configLocation);
-        try (final InputStream inputStream = Files.newInputStream(Paths.get(configLocation))) {
-            final ConfigurationSource source = new ConfigurationSource(inputStream, file);
+        final Path path = Paths.get(configLocation);
+        try (final InputStream inputStream = Files.newInputStream(path)) {
+            final ConfigurationSource source = new ConfigurationSource(inputStream, path);
             final LoggerContext context = (LoggerContext) org.apache.logging.log4j.LogManager.getContext(false);
             Configuration configuration = null;
             if (configLocation.endsWith(PropertiesConfigurationFactory.FILE_EXTENSION)) {

[logging-log4j2] 01/03: Add ConfigurationSource.ConfigurationSource(InputStream, Path).

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 83b3468d16217700b52715c52c8e92607a5120b9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 19 18:01:40 2022 -0500

    Add ConfigurationSource.ConfigurationSource(InputStream, Path).
---
 .../log4j/core/config/ConfigurationSource.java     | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
index be931c5..c1616eb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
@@ -29,6 +29,8 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Objects;
 
 import javax.net.ssl.HttpsURLConnection;
@@ -90,6 +92,26 @@ public class ConfigurationSource {
 
     /**
      * Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
+     * path.
+     *
+     * @param stream the input stream, the caller is responsible for closing this resource.
+     * @param path the path where the input stream originated.
+     */
+    public ConfigurationSource(final InputStream stream, final Path path) {
+        this.stream = Objects.requireNonNull(stream, "stream is null");
+        this.data = null;
+        this.source = new Source(path);
+        long modified = 0;
+        try {
+            modified = Files.getLastModifiedTime(path).toMillis();
+        } catch (Exception ex) {
+            // There is a problem with the file. It will be handled somewhere else.
+        }
+        this.lastModified = modified;
+    }
+
+    /**
+     * Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
      * url.
      *
      * @param stream the input stream, the caller is responsible for closing this resource.