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/12 19:08:04 UTC

[logging-log4j2] branch master updated (263763a -> f314a1c)

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

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


    from 263763a  [LOG4J2-3330] Configurator.setLevel not fetching the correct LoggerContext.
     new 1ce326a  Minor bullet-proofing for WIP.
     new f66e6b5  Our convention is to make test classes public.
     new 938206c  Increase timeout to attempt to fix GitHub action builds.
     new f314a1c  Remove duplicate data carried in ConfigurationSource.

The 4 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:
 .../core/net/SocketAppenderReconnectTest.java      |   2 +-
 .../log4j/core/config/AbstractConfiguration.java   |   2 +-
 .../log4j/core/config/ConfigurationSource.java     | 109 +++++++++------------
 .../log4j/smtp/appender/SmtpManagerTest.java       |   2 +-
 4 files changed, 48 insertions(+), 67 deletions(-)

[logging-log4j2] 03/04: Increase timeout to attempt to fix GitHub action builds.

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

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

commit 938206c741133a92d1d205f6641d20fa753cb659
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 12 13:08:12 2022 -0500

    Increase timeout to attempt to fix GitHub action builds.
    
    Port from release-2.x.
---
 .../org/apache/logging/log4j/core/net/SocketAppenderReconnectTest.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/SocketAppenderReconnectTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/SocketAppenderReconnectTest.java
index 5fa603f..7e6df36 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/SocketAppenderReconnectTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/net/SocketAppenderReconnectTest.java
@@ -201,7 +201,7 @@ class SocketAppenderReconnectTest {
     private static void awaitUntilSucceeds(final Runnable runnable) {
         // These figures are collected via trial-and-error; nothing scientific to look for here.
         final long pollIntervalMillis = 1_000L;
-        final long timeoutSeconds = 15L;
+        final long timeoutSeconds = 60L;
         await()
                 .pollInterval(pollIntervalMillis, TimeUnit.MILLISECONDS)
                 .atMost(timeoutSeconds, TimeUnit.SECONDS)

[logging-log4j2] 02/04: Our convention is to make test classes public.

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

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

commit f66e6b53e7eaee0c45d004f7e9961ff04b63c3f4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 12 13:06:20 2022 -0500

    Our convention is to make test classes public.
    
    Port from release-2.x.
---
 .../java/org/apache/logging/log4j/smtp/appender/SmtpManagerTest.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log4j-smtp/src/test/java/org/apache/logging/log4j/smtp/appender/SmtpManagerTest.java b/log4j-smtp/src/test/java/org/apache/logging/log4j/smtp/appender/SmtpManagerTest.java
index 699a0ba..b63a549 100644
--- a/log4j-smtp/src/test/java/org/apache/logging/log4j/smtp/appender/SmtpManagerTest.java
+++ b/log4j-smtp/src/test/java/org/apache/logging/log4j/smtp/appender/SmtpManagerTest.java
@@ -35,7 +35,7 @@ import org.junit.jupiter.api.Test;
 /**
  * Unit tests for {@link SmtpManager}.
  */
-class SmtpManagerTest {
+public class SmtpManagerTest {
 
     @Test
     void testCreateManagerName() {

[logging-log4j2] 04/04: Remove duplicate data carried in ConfigurationSource.

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

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

commit f314a1c9a50f31af37cdde3959682332436987c1
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 12 12:01:05 2022 -0500

    Remove duplicate data carried in ConfigurationSource.
    
    Deprecated unused API.
    
    Port from release-2.x.
---
 .../log4j/core/config/ConfigurationSource.java     | 109 +++++++++------------
 1 file changed, 45 insertions(+), 64 deletions(-)

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 36ca3ab..2b6feb3 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
@@ -60,9 +60,6 @@ public class ConfigurationSource {
     private static final String HTTPS = "https";
     private static final String HTTP = "http";
 
-    private final File file;
-    private final URL url;
-    private final String location;
     private final InputStream stream;
     private volatile byte[] data;
     private volatile Source source;
@@ -74,15 +71,13 @@ public class ConfigurationSource {
      * Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
      * file.
      *
-     * @param stream the input stream
+     * @param stream the input stream, the caller is responsible for closing this resource.
      * @param file the file where the input stream originated
      */
     public ConfigurationSource(final InputStream stream, final File file) {
         this.stream = Objects.requireNonNull(stream, "stream is null");
-        this.file = Objects.requireNonNull(file, "file is null");
-        this.location = file.getAbsolutePath();
-        this.url = null;
         this.data = null;
+        this.source = new Source(file);
         long modified = 0;
         try {
             modified = file.lastModified();
@@ -98,38 +93,34 @@ public class ConfigurationSource {
      *
      * @param stream the input stream
      * @param url the URL where the input stream originated
-     * @param lastModified when the source was last modified.
      */
-    public ConfigurationSource(final InputStream stream, final URL url, final long lastModified) {
+    public ConfigurationSource(final InputStream stream, final URL url) {
         this.stream = Objects.requireNonNull(stream, "stream is null");
-        this.url = Objects.requireNonNull(url, "URL is null");
-        this.location = url.toString();
-        this.file = null;
         this.data = null;
-        this.lastModified = lastModified;
+        this.lastModified = 0;
+        this.source = new Source(url);
     }
 
     /**
      * Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
      * url.
      *
-     * @param stream the input stream
+     * @param stream the input stream, the caller is responsible for closing this resource.
      * @param url the URL where the input stream originated
+     * @param lastModified when the source was last modified.
      */
-    public ConfigurationSource(final InputStream stream, final URL url) {
+    public ConfigurationSource(final InputStream stream, final URL url, long lastModified) {
         this.stream = Objects.requireNonNull(stream, "stream is null");
-        this.url = Objects.requireNonNull(url, "URL is null");
-        this.location = url.toString();
-        this.file = null;
         this.data = null;
-        this.lastModified = 0;
+        this.lastModified = lastModified;
+        this.source = new Source(url);
     }
 
     /**
      * Constructs a new {@code ConfigurationSource} with the specified input stream. Since the stream is the only source
      * of data, this constructor makes a copy of the stream contents.
      *
-     * @param stream the input stream
+     * @param stream the input stream, the caller is responsible for closing this resource.
      * @throws IOException if an exception occurred reading from the specified stream
      */
     public ConfigurationSource(final InputStream stream) throws IOException {
@@ -140,21 +131,18 @@ public class ConfigurationSource {
         Objects.requireNonNull(source, "source is null");
         this.data = Objects.requireNonNull(data, "data is null");
         this.stream = new ByteArrayInputStream(data);
-        this.file = source.getFile();
-        this.url = source.getURI().toURL();
-        this.location = source.getLocation();
         this.lastModified = lastModified;
+        this.source = source;
     }
 
     private ConfigurationSource(final byte[] data, final URL url, final long lastModified) {
         this.data = Objects.requireNonNull(data, "data is null");
         this.stream = new ByteArrayInputStream(data);
-        this.file = null;
-        this.url = url;
-        this.location = null;
         this.lastModified = lastModified;
-        if ( url == null ) {
-        	this.data = data;
+        if (url == null) {
+            this.data = data;
+        } else {
+            this.source = new Source(url);
         }
     }
 
@@ -185,9 +173,21 @@ public class ConfigurationSource {
      * @return the configuration source file, or {@code null}
      */
     public File getFile() {
-        return file;
+        return source == null ? null : source.getFile();
     }
 
+    private boolean isFile() {
+        return source == null ? false : source.getFile() != null;
+    }
+    
+    private boolean isURL() {
+        return source == null ? false : source.getURI() != null;
+    }
+    
+    private boolean isLocation() {
+        return source == null ? false : source.getLocation() != null;
+    }
+    
     /**
      * Returns the configuration source URL, or {@code null} if this configuration source is based on a file or has
      * neither a file nor an URL.
@@ -195,10 +195,14 @@ public class ConfigurationSource {
      * @return the configuration source URL, or {@code null}
      */
     public URL getURL() {
-        return url;
+        return source == null ? null : source.getURL();
     }
 
-    public void setSource(final Source source) {
+    /**
+     * @deprecated Not used internally, no replacement. TODO remove and make source final.
+     */
+    @Deprecated
+    public void setSource(Source source) {
         this.source = source;
     }
 
@@ -215,30 +219,7 @@ public class ConfigurationSource {
      * @return The URI.
      */
     public URI getURI() {
-        URI sourceURI = null;
-        if (url != null) {
-            try {
-                sourceURI = url.toURI();
-            } catch (final URISyntaxException ex) {
-                    /* Ignore the exception */
-            }
-        }
-        if (sourceURI == null && file != null) {
-            sourceURI = file.toURI();
-        }
-        if (sourceURI == null && location != null) {
-            try {
-                sourceURI = new URI(location);
-            } catch (final URISyntaxException ex) {
-                // Assume the scheme was missing.
-                try {
-                    sourceURI = new URI("file://" + location);
-                } catch (final URISyntaxException uriEx) {
-                    /* Ignore the exception */
-                }
-            }
-        }
-        return sourceURI;
+        return source == null ? null : source.getURI();
     }
 
     /**
@@ -256,7 +237,7 @@ public class ConfigurationSource {
      * @return a string describing the configuration source file or URL, or {@code null}
      */
     public String getLocation() {
-        return location;
+        return source == null ? null : source.getLocation();
     }
 
     /**
@@ -275,14 +256,14 @@ public class ConfigurationSource {
      * @throws IOException if a problem occurred while opening the new input stream
      */
     public ConfigurationSource resetInputStream() throws IOException {
-        if (source != null) {
+        if (source != null && data != null) {
             return new ConfigurationSource(source, data, this.lastModified);
-        } else if (file != null) {
-            return new ConfigurationSource(new FileInputStream(file), file);
-        } else if (url != null && data != null) {
+        } else if (isFile()) {
+            return new ConfigurationSource(new FileInputStream(getFile()), getFile());
+        } else if (isURL() && data != null) {
             // Creates a ConfigurationSource without accessing the URL since the data was provided.
-            return new ConfigurationSource(data, url, modifiedMillis == 0 ? lastModified : modifiedMillis);
-        } else if (url != null) {
+            return new ConfigurationSource(data, getURL(), modifiedMillis == 0 ? lastModified : modifiedMillis);
+        } else if (isURL()) {
             return fromUri(getURI());
         } else if (data != null) {
             return new ConfigurationSource(data, null, lastModified);
@@ -292,8 +273,8 @@ public class ConfigurationSource {
 
     @Override
     public String toString() {
-        if (location != null) {
-            return location;
+        if (isLocation()) {
+            return getLocation();
         }
         if (this == NULL_SOURCE) {
             return "NULL_SOURCE";

[logging-log4j2] 01/04: Minor bullet-proofing for WIP.

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

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

commit 1ce326ad757f189dea7af112ebd7e1dae961c1f5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 12 11:58:00 2022 -0500

    Minor bullet-proofing for WIP.
    
    Port commit e3fd782471c97b0b7af3fb7089c90bd658224daf from release-2.x.
---
 .../org/apache/logging/log4j/core/config/AbstractConfiguration.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index 126e142..77bc1ec 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -256,7 +256,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
 
     protected void initializeWatchers(final Reconfigurable reconfigurable, final ConfigurationSource configSource,
                  final int monitorIntervalSeconds) {
-        if (configSource.getFile() != null || configSource.getURL() != null) {
+        if (configSource != null && (configSource.getFile() != null || configSource.getURL() != null)) {
             if (monitorIntervalSeconds > 0) {
                 watchManager.setIntervalSeconds(monitorIntervalSeconds);
                 if (configSource.getFile() != null) {