[logging-log4j2] branch master updated (e32cdde -> 5da8b9c)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from e32cdde [LOG4J2-2653] Migrate more tests to JUnit 5 add 5da8b9c Bump assertj-core from 3.14.0 to 3.17.1 No new revisions were added by this update. Summary of changes: pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] branch master updated (5da8b9c -> 508ec22)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 5da8b9c Bump assertj-core from 3.14.0 to 3.17.1 add 508ec22 Bump jeromq from 0.4.3 to 0.5.2 No new revisions were added by this update. Summary of changes: pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] branch master updated (5da8b9c -> 508ec22)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 5da8b9c Bump assertj-core from 3.14.0 to 3.17.1 add 508ec22 Bump jeromq from 0.4.3 to 0.5.2 No new revisions were added by this update. Summary of changes: pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] branch release-2.x updated: Try improving RollingDirectTimeNewDirectoryTest to alleviate test report failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 704b16f Try improving RollingDirectTimeNewDirectoryTest to alleviate test report failures. 704b16f is described below commit 704b16f32098057c4c7f079f33fa7e090310f6a2 Author: Volkan Yazıcı AuthorDate: Wed Aug 26 09:03:01 2020 +0200 Try improving RollingDirectTimeNewDirectoryTest to alleviate test report failures. --- .../rolling/RollingDirectTimeNewDirectoryTest.java | 71 +++--- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java index 8372a7e..c1a2667 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java @@ -16,42 +16,41 @@ */ package org.apache.logging.log4j.core.appender.rolling; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.junit.LoggerContextRule; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import java.io.File; +import java.util.Arrays; +import java.util.Iterator; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -/** - * Tests - */ public class RollingDirectTimeNewDirectoryTest { + private static final String CONFIG = "log4j-rolling-folder-direct.xml"; +// Note that the path is hardcoded in the configuration! private static final String DIR = "target/rolling-folder-direct"; -public static LoggerContextRule loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); +public static LoggerContextRule loggerContextRule = +LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); @Rule public RuleChain chain = loggerContextRule.withCleanFoldersRule(DIR); -private Logger logger; - -@Before -public void setUp() throws Exception { -this.logger = loggerContextRule.getLogger(RollingDirectTimeNewDirectoryTest.class.getName()); -} - - @Test public void streamClosedError() throws Exception { + +final Logger logger = +loggerContextRule.getLogger( +RollingDirectTimeNewDirectoryTest.class.getName()); + for (int i = 0; i < 1000; i++) { logger.info("nHq6p9kgfvWfjzDRYbZp"); } @@ -60,14 +59,42 @@ public class RollingDirectTimeNewDirectoryTest { logger.info("nHq6p9kgfvWfjzDRYbZp"); } -File tempDirectoryAsFile = new File(DIR); -File[] loggingFolders = tempDirectoryAsFile.listFiles(); -assertNotNull(loggingFolders); -// Check if two folders were created -assertTrue("Not enough directories created", loggingFolders.length >= 2); -for (File dir : loggingFolders) { -File[] files = dir.listFiles(); -assertTrue("No files in directory " + dir.toString(), files != null && files.length > 0); +File logDir = new File(DIR); +File[] logFolders = logDir.listFiles(); +assertNotNull(logFolders); +Arrays.sort(logFolders); + +try { + +final int minExpectedLogFolderCount = 2; +assertTrue( +"was expecting at least " + minExpectedLogFolderCount + " folders, " + +"found " + logFolders.length, +logFolders.length >= minExpectedLogFolderCount); + +for (File logFolder : logFolders) { +File[] logFiles = logFolder.listFiles(); +if (logFiles != null) { +Arrays.sort(logFiles); +} +assertTrue("empty folder: " + logFolder, logFiles != null && logFiles.length > 0); +} + +} catch (AssertionError error) { +System.out.format("log directory (%s) contents:%n", DIR); +final Iterator fileIterator = +FileUtils.iterateFilesAndDirs( +logDir, TrueFileFilter.TRUE, TrueFileFilter.TRUE); +int totalFileCount = 0; +while (fileIterator.hasNext()) { +totalFileCount++; +final File file
[logging-log4j2] branch release-2.x updated: Try improving RollingDirectTimeNewDirectoryTest to alleviate test report failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 704b16f Try improving RollingDirectTimeNewDirectoryTest to alleviate test report failures. 704b16f is described below commit 704b16f32098057c4c7f079f33fa7e090310f6a2 Author: Volkan Yazıcı AuthorDate: Wed Aug 26 09:03:01 2020 +0200 Try improving RollingDirectTimeNewDirectoryTest to alleviate test report failures. --- .../rolling/RollingDirectTimeNewDirectoryTest.java | 71 +++--- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java index 8372a7e..c1a2667 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectTimeNewDirectoryTest.java @@ -16,42 +16,41 @@ */ package org.apache.logging.log4j.core.appender.rolling; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.junit.LoggerContextRule; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import java.io.File; +import java.util.Arrays; +import java.util.Iterator; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -/** - * Tests - */ public class RollingDirectTimeNewDirectoryTest { + private static final String CONFIG = "log4j-rolling-folder-direct.xml"; +// Note that the path is hardcoded in the configuration! private static final String DIR = "target/rolling-folder-direct"; -public static LoggerContextRule loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); +public static LoggerContextRule loggerContextRule = +LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); @Rule public RuleChain chain = loggerContextRule.withCleanFoldersRule(DIR); -private Logger logger; - -@Before -public void setUp() throws Exception { -this.logger = loggerContextRule.getLogger(RollingDirectTimeNewDirectoryTest.class.getName()); -} - - @Test public void streamClosedError() throws Exception { + +final Logger logger = +loggerContextRule.getLogger( +RollingDirectTimeNewDirectoryTest.class.getName()); + for (int i = 0; i < 1000; i++) { logger.info("nHq6p9kgfvWfjzDRYbZp"); } @@ -60,14 +59,42 @@ public class RollingDirectTimeNewDirectoryTest { logger.info("nHq6p9kgfvWfjzDRYbZp"); } -File tempDirectoryAsFile = new File(DIR); -File[] loggingFolders = tempDirectoryAsFile.listFiles(); -assertNotNull(loggingFolders); -// Check if two folders were created -assertTrue("Not enough directories created", loggingFolders.length >= 2); -for (File dir : loggingFolders) { -File[] files = dir.listFiles(); -assertTrue("No files in directory " + dir.toString(), files != null && files.length > 0); +File logDir = new File(DIR); +File[] logFolders = logDir.listFiles(); +assertNotNull(logFolders); +Arrays.sort(logFolders); + +try { + +final int minExpectedLogFolderCount = 2; +assertTrue( +"was expecting at least " + minExpectedLogFolderCount + " folders, " + +"found " + logFolders.length, +logFolders.length >= minExpectedLogFolderCount); + +for (File logFolder : logFolders) { +File[] logFiles = logFolder.listFiles(); +if (logFiles != null) { +Arrays.sort(logFiles); +} +assertTrue("empty folder: " + logFolder, logFiles != null && logFiles.length > 0); +} + +} catch (AssertionError error) { +System.out.format("log directory (%s) contents:%n", DIR); +final Iterator fileIterator = +FileUtils.iterateFilesAndDirs( +logDir, TrueFileFilter.TRUE, TrueFileFilter.TRUE); +int totalFileCount = 0; +while (fileIterator.hasNext()) { +totalFileCount++; +final File file
[logging-log4j2] branch master updated (05288f4 -> 4052a1c)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 05288f4 #335 Add Velocity support to JsonTemplateLayout manual. add 96956a2 #335 Rename JsonTemplateLayout artifact and package. add 58d9b49 Try improving RollingAppenderRestartTest to alleviate test report failures. add 4052a1c Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures. No new revisions were added by this update. Summary of changes: log4j-bom/pom.xml | 2 +- .../rolling/RollingAppenderRestartTest.java| 48 +++ .../RollingDirectSizeTimeNewDirectoryTest.java | 93 +- .../pom.xml| 2 +- .../layout/template/json}/JsonTemplateLayout.java | 19 +++-- .../template/json}/JsonTemplateLayoutDefaults.java | 6 +- .../json}/resolver/EndOfBatchResolver.java | 4 +- .../json}/resolver/EndOfBatchResolverFactory.java | 2 +- .../template/json}/resolver/EventResolver.java | 2 +- .../json}/resolver/EventResolverContext.java | 10 +-- .../json}/resolver/EventResolverFactories.java | 2 +- .../json}/resolver/EventResolverFactory.java | 2 +- .../resolver/ExceptionInternalResolverFactory.java | 2 +- .../template/json}/resolver/ExceptionResolver.java | 7 +- .../json}/resolver/ExceptionResolverFactory.java | 2 +- .../json}/resolver/ExceptionRootCauseResolver.java | 7 +- .../ExceptionRootCauseResolverFactory.java | 2 +- .../template/json}/resolver/LevelResolver.java | 4 +- .../json}/resolver/LevelResolverFactory.java | 2 +- .../template/json}/resolver/LoggerResolver.java| 4 +- .../json}/resolver/LoggerResolverFactory.java | 2 +- .../template/json}/resolver/MainMapResolver.java | 4 +- .../json}/resolver/MainMapResolverFactory.java | 2 +- .../template/json}/resolver/MapResolver.java | 4 +- .../json}/resolver/MapResolverFactory.java | 2 +- .../template/json}/resolver/MarkerResolver.java| 4 +- .../json}/resolver/MarkerResolverFactory.java | 2 +- .../template/json}/resolver/MessageResolver.java | 5 +- .../json}/resolver/MessageResolverFactory.java | 2 +- .../template/json}/resolver/PatternResolver.java | 7 +- .../json}/resolver/PatternResolverFactory.java | 2 +- .../template/json}/resolver/SourceResolver.java| 7 +- .../json}/resolver/SourceResolverFactory.java | 2 +- .../resolver/StackTraceElementObjectResolver.java | 4 +- .../StackTraceElementObjectResolverContext.java| 4 +- .../StackTraceElementObjectResolverFactories.java | 2 +- .../StackTraceElementObjectResolverFactory.java| 2 +- .../json}/resolver/StackTraceObjectResolver.java | 4 +- .../json}/resolver/StackTraceResolver.java | 2 +- .../json}/resolver/StackTraceStringResolver.java | 8 +- .../template/json}/resolver/TemplateResolver.java | 4 +- .../json}/resolver/TemplateResolverConfig.java | 4 +- .../json}/resolver/TemplateResolverContext.java| 4 +- .../json}/resolver/TemplateResolverFactory.java| 2 +- .../template/json}/resolver/TemplateResolvers.java | 8 +- .../json}/resolver/ThreadContextDataResolver.java | 8 +- .../resolver/ThreadContextDataResolverFactory.java | 2 +- .../json}/resolver/ThreadContextStackResolver.java | 4 +- .../ThreadContextStackResolverFactory.java | 2 +- .../template/json}/resolver/ThreadResolver.java| 4 +- .../json}/resolver/ThreadResolverFactory.java | 2 +- .../template/json}/resolver/TimestampResolver.java | 6 +- .../json}/resolver/TimestampResolverFactory.java | 2 +- .../layout/template/json}/util/DummyRecycler.java | 2 +- .../template/json}/util/DummyRecyclerFactory.java | 2 +- .../layout/template/json}/util/JsonReader.java | 2 +- .../layout/template/json}/util/JsonWriter.java | 2 +- .../layout/template/json}/util/MapAccessor.java| 2 +- .../template/json}/util/QueueingRecycler.java | 2 +- .../json}/util/QueueingRecyclerFactory.java| 2 +- .../log4j/layout/template/json}/util/Recycler.java | 2 +- .../template/json}/util/RecyclerFactories.java | 2 +- .../template/json}/util/RecyclerFactory.java | 2 +- .../template/json}/util/StringParameterParser.java | 2 +- .../template/json}/util/ThreadLocalRecycler.java | 2 +- .../json}/util/ThreadLocalRecyclerFactory.java | 2 +- .../json}/util/TruncatingBufferedPrintWriter.java | 2 +- .../json}/util/TruncatingBufferedWriter.java | 2 +- .../log4j/layout/template/json}/util/Uris.java | 2 +- .../src/main/resources/EcsLayout.json | 0 .../src/main/resources/GelfLayout.json | 0 .../src/main/resources/JsonLayout.json | 0 .../main/resources/LogstashJsonEventLayoutV1.json | 0
[logging-log4j2] branch master updated (05288f4 -> 4052a1c)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 05288f4 #335 Add Velocity support to JsonTemplateLayout manual. add 96956a2 #335 Rename JsonTemplateLayout artifact and package. add 58d9b49 Try improving RollingAppenderRestartTest to alleviate test report failures. add 4052a1c Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures. No new revisions were added by this update. Summary of changes: log4j-bom/pom.xml | 2 +- .../rolling/RollingAppenderRestartTest.java| 48 +++ .../RollingDirectSizeTimeNewDirectoryTest.java | 93 +- .../pom.xml| 2 +- .../layout/template/json}/JsonTemplateLayout.java | 19 +++-- .../template/json}/JsonTemplateLayoutDefaults.java | 6 +- .../json}/resolver/EndOfBatchResolver.java | 4 +- .../json}/resolver/EndOfBatchResolverFactory.java | 2 +- .../template/json}/resolver/EventResolver.java | 2 +- .../json}/resolver/EventResolverContext.java | 10 +-- .../json}/resolver/EventResolverFactories.java | 2 +- .../json}/resolver/EventResolverFactory.java | 2 +- .../resolver/ExceptionInternalResolverFactory.java | 2 +- .../template/json}/resolver/ExceptionResolver.java | 7 +- .../json}/resolver/ExceptionResolverFactory.java | 2 +- .../json}/resolver/ExceptionRootCauseResolver.java | 7 +- .../ExceptionRootCauseResolverFactory.java | 2 +- .../template/json}/resolver/LevelResolver.java | 4 +- .../json}/resolver/LevelResolverFactory.java | 2 +- .../template/json}/resolver/LoggerResolver.java| 4 +- .../json}/resolver/LoggerResolverFactory.java | 2 +- .../template/json}/resolver/MainMapResolver.java | 4 +- .../json}/resolver/MainMapResolverFactory.java | 2 +- .../template/json}/resolver/MapResolver.java | 4 +- .../json}/resolver/MapResolverFactory.java | 2 +- .../template/json}/resolver/MarkerResolver.java| 4 +- .../json}/resolver/MarkerResolverFactory.java | 2 +- .../template/json}/resolver/MessageResolver.java | 5 +- .../json}/resolver/MessageResolverFactory.java | 2 +- .../template/json}/resolver/PatternResolver.java | 7 +- .../json}/resolver/PatternResolverFactory.java | 2 +- .../template/json}/resolver/SourceResolver.java| 7 +- .../json}/resolver/SourceResolverFactory.java | 2 +- .../resolver/StackTraceElementObjectResolver.java | 4 +- .../StackTraceElementObjectResolverContext.java| 4 +- .../StackTraceElementObjectResolverFactories.java | 2 +- .../StackTraceElementObjectResolverFactory.java| 2 +- .../json}/resolver/StackTraceObjectResolver.java | 4 +- .../json}/resolver/StackTraceResolver.java | 2 +- .../json}/resolver/StackTraceStringResolver.java | 8 +- .../template/json}/resolver/TemplateResolver.java | 4 +- .../json}/resolver/TemplateResolverConfig.java | 4 +- .../json}/resolver/TemplateResolverContext.java| 4 +- .../json}/resolver/TemplateResolverFactory.java| 2 +- .../template/json}/resolver/TemplateResolvers.java | 8 +- .../json}/resolver/ThreadContextDataResolver.java | 8 +- .../resolver/ThreadContextDataResolverFactory.java | 2 +- .../json}/resolver/ThreadContextStackResolver.java | 4 +- .../ThreadContextStackResolverFactory.java | 2 +- .../template/json}/resolver/ThreadResolver.java| 4 +- .../json}/resolver/ThreadResolverFactory.java | 2 +- .../template/json}/resolver/TimestampResolver.java | 6 +- .../json}/resolver/TimestampResolverFactory.java | 2 +- .../layout/template/json}/util/DummyRecycler.java | 2 +- .../template/json}/util/DummyRecyclerFactory.java | 2 +- .../layout/template/json}/util/JsonReader.java | 2 +- .../layout/template/json}/util/JsonWriter.java | 2 +- .../layout/template/json}/util/MapAccessor.java| 2 +- .../template/json}/util/QueueingRecycler.java | 2 +- .../json}/util/QueueingRecyclerFactory.java| 2 +- .../log4j/layout/template/json}/util/Recycler.java | 2 +- .../template/json}/util/RecyclerFactories.java | 2 +- .../template/json}/util/RecyclerFactory.java | 2 +- .../template/json}/util/StringParameterParser.java | 2 +- .../template/json}/util/ThreadLocalRecycler.java | 2 +- .../json}/util/ThreadLocalRecyclerFactory.java | 2 +- .../json}/util/TruncatingBufferedPrintWriter.java | 2 +- .../json}/util/TruncatingBufferedWriter.java | 2 +- .../log4j/layout/template/json}/util/Uris.java | 2 +- .../src/main/resources/EcsLayout.json | 0 .../src/main/resources/GelfLayout.json | 0 .../src/main/resources/JsonLayout.json | 0 .../main/resources/LogstashJsonEventLayoutV1.json | 0
[logging-log4j2] 01/01: Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit fcedbb2834da27948477fdb96403fe2d8b1f15af Author: Volkan Yazıcı AuthorDate: Tue Aug 25 16:22:40 2020 +0200 Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures. --- .../RollingDirectSizeTimeNewDirectoryTest.java | 93 +- pom.xml| 2 +- 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java index 9978aa8..9afbfa9 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java @@ -16,47 +16,39 @@ */ package org.apache.logging.log4j.core.appender.rolling; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.junit.LoggerContextRule; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import java.io.File; import java.util.Arrays; -import java.util.List; +import java.util.Iterator; -import static java.util.Arrays.asList; -import static java.util.Collections.sort; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; -/** - * Tests - */ public class RollingDirectSizeTimeNewDirectoryTest { + private static final String CONFIG = "log4j-rolling-size-time-new-directory.xml"; +// Note that the path is hardcoded in the configuration! private static final String DIR = "target/rolling-size-time-new-directory"; -public static LoggerContextRule loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); +public static LoggerContextRule loggerContextRule = +LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); @Rule public RuleChain chain = loggerContextRule.withCleanFoldersRule(DIR); -private Logger logger; - -@Before -public void setUp() throws Exception { -this.logger = loggerContextRule.getLogger(RollingDirectSizeTimeNewDirectoryTest.class.getName()); -} - - @Test public void streamClosedError() throws Exception { + +final Logger logger = + loggerContextRule.getLogger(RollingDirectSizeTimeNewDirectoryTest.class); + for (int i = 0; i < 1000; i++) { logger.info("nHq6p9kgfvWfjzDRYbZp"); } @@ -65,25 +57,52 @@ public class RollingDirectSizeTimeNewDirectoryTest { logger.info("nHq6p9kgfvWfjzDRYbZp"); } -File tempDirectoryAsFile = new File(DIR); -File[] loggingFolders = tempDirectoryAsFile.listFiles(); -assertNotNull(loggingFolders); -// Check if two folders were created -assertTrue("Not enough directories created", loggingFolders.length >= 2); -Arrays.sort(loggingFolders); -for (int i = 0; i < loggingFolders.length; ++i) { -File dir = loggingFolders[i]; -File[] files = dir.listFiles(); -assertTrue("No files in directory " + dir.toString(), files != null && files.length > 0); -if (i > 0 && i < loggingFolders.length - 1) { -if (files.length < 3) { -System.out.println("Only " + files.length + " files created in " + dir.toString()); -for (File logFile : files) { -System.out.println("File name: " + logFile.getName() + " size: " + logFile.length()); -} -fail(); +final File logDir = new File(DIR); +final File[] logFolders = logDir.listFiles(); +assertNotNull(logFolders); +Arrays.sort(logFolders); + +try { + +final int minExpectedLogFolderCount = 2; +assertTrue( +"was expecting at least " + minExpectedLogFolderCount + " folders, " + +"found " + logFolders.length, +logFolders.length >= minExpectedLogFolderCount); + +for (int logFolderIndex = 0; logFolderIndex < logFolders.length; ++logFolderIndex) { + +File logFolder = logFold
[logging-log4j2] branch master updated (4052a1c -> fcedbb2)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. omit 4052a1c Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures. new fcedbb2 Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures. This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (4052a1c) \ N -- N -- N refs/heads/master (fcedbb2) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 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: pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] branch master updated (fcedbb2 -> 916b13f)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from fcedbb2 Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures. add 916b13f Bump jackson2Version from 2.11.1 to 2.11.2 No new revisions were added by this update. Summary of changes: pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] branch master updated (916b13f -> 3751f85)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 916b13f Bump jackson2Version from 2.11.1 to 2.11.2 add 3751f85 Bump commons-compress from 1.18 to 1.20 No new revisions were added by this update. Summary of changes: pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] branch release-2.x updated: #335 Rename JsonTemplateLayout artifact and package.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 4e70878 #335 Rename JsonTemplateLayout artifact and package. 4e70878 is described below commit 4e70878a6354c3394d47bc0c99f4a41997683082 Author: Volkan Yazıcı AuthorDate: Tue Aug 25 10:25:51 2020 +0200 #335 Rename JsonTemplateLayout artifact and package. --- log4j-bom/pom.xml | 2 +- .../pom.xml| 12 ++-- .../revapi.json| 0 .../layout/template/json}/JsonTemplateLayout.java | 18 +- .../template/json}/JsonTemplateLayoutDefaults.java | 6 +++--- .../template/json}/resolver/EndOfBatchResolver.java| 4 ++-- .../json}/resolver/EndOfBatchResolverFactory.java | 2 +- .../layout/template/json}/resolver/EventResolver.java | 2 +- .../template/json}/resolver/EventResolverContext.java | 10 -- .../json}/resolver/EventResolverFactories.java | 2 +- .../template/json}/resolver/EventResolverFactory.java | 2 +- .../resolver/ExceptionInternalResolverFactory.java | 2 +- .../template/json}/resolver/ExceptionResolver.java | 7 --- .../json}/resolver/ExceptionResolverFactory.java | 2 +- .../json}/resolver/ExceptionRootCauseResolver.java | 7 --- .../resolver/ExceptionRootCauseResolverFactory.java| 2 +- .../layout/template/json}/resolver/LevelResolver.java | 4 ++-- .../template/json}/resolver/LevelResolverFactory.java | 2 +- .../layout/template/json}/resolver/LoggerResolver.java | 4 ++-- .../template/json}/resolver/LoggerResolverFactory.java | 2 +- .../template/json}/resolver/MainMapResolver.java | 4 ++-- .../json}/resolver/MainMapResolverFactory.java | 2 +- .../layout/template/json}/resolver/MapResolver.java| 4 ++-- .../template/json}/resolver/MapResolverFactory.java| 2 +- .../layout/template/json}/resolver/MarkerResolver.java | 4 ++-- .../template/json}/resolver/MarkerResolverFactory.java | 2 +- .../template/json}/resolver/MessageResolver.java | 4 ++-- .../json}/resolver/MessageResolverFactory.java | 2 +- .../template/json}/resolver/PatternResolver.java | 7 --- .../json}/resolver/PatternResolverFactory.java | 2 +- .../layout/template/json}/resolver/SourceResolver.java | 7 --- .../template/json}/resolver/SourceResolverFactory.java | 2 +- .../resolver/StackTraceElementObjectResolver.java | 4 ++-- .../StackTraceElementObjectResolverContext.java| 4 ++-- .../StackTraceElementObjectResolverFactories.java | 2 +- .../StackTraceElementObjectResolverFactory.java| 2 +- .../json}/resolver/StackTraceObjectResolver.java | 4 ++-- .../template/json}/resolver/StackTraceResolver.java| 2 +- .../json}/resolver/StackTraceStringResolver.java | 8 .../template/json}/resolver/TemplateResolver.java | 4 ++-- .../json}/resolver/TemplateResolverConfig.java | 4 ++-- .../json}/resolver/TemplateResolverContext.java| 4 ++-- .../json}/resolver/TemplateResolverFactory.java| 2 +- .../template/json}/resolver/TemplateResolvers.java | 8 .../json}/resolver/ThreadContextDataResolver.java | 8 .../resolver/ThreadContextDataResolverFactory.java | 2 +- .../json}/resolver/ThreadContextStackResolver.java | 4 ++-- .../resolver/ThreadContextStackResolverFactory.java| 2 +- .../layout/template/json}/resolver/ThreadResolver.java | 4 ++-- .../template/json}/resolver/ThreadResolverFactory.java | 2 +- .../template/json}/resolver/TimestampResolver.java | 6 +++--- .../json}/resolver/TimestampResolverFactory.java | 2 +- .../layout/template/json}/util/DummyRecycler.java | 2 +- .../template/json}/util/DummyRecyclerFactory.java | 2 +- .../log4j/layout/template/json}/util/JsonReader.java | 2 +- .../log4j/layout/template/json}/util/JsonWriter.java | 2 +- .../log4j/layout/template/json}/util/MapAccessor.java | 2 +- .../layout/template/json}/util/QueueingRecycler.java | 2 +- .../template/json}/util/QueueingRecyclerFactory.java | 2 +- .../log4j/layout/template/json}/util/Recycler.java | 2 +- .../layout/template/json}/util/RecyclerFactories.java | 2 +- .../layout/template/json}/util/RecyclerFactory.java| 2 +- .../template/json}/util/StringParameterParser.java | 2 +- .../template/json}/util/ThreadLocalRecycler.java | 2 +- .../json}/util/ThreadLocalRecyclerFactory.java | 2 +- .../json}/util/TruncatingBufferedPrintWriter.java | 2 +- .../template/json}/util/TruncatingBufferedWriter.java | 2 +- .../logging/log4j/layout/template/json}/util/Uris.java | 2 +- .../src
[logging-log4j2] 02/02: #335 Migrate JsonTemplateLayout manual from Xdoc to AsciiDoc.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 20d5463ab4114b12c4c95a8704fd5cbabfc17949 Author: Volkan Yazıcı AuthorDate: Tue Aug 25 09:22:00 2020 +0200 #335 Migrate JsonTemplateLayout manual from Xdoc to AsciiDoc. --- ...te-layout.adoc => json-template-layout.adoc.vm} | 344 ++--- src/site/xdoc/manual/json-template-layout.xml.vm | 1526 2 files changed, 177 insertions(+), 1693 deletions(-) diff --git a/src/site/asciidoc/manual/json-template-layout.adoc b/src/site/asciidoc/manual/json-template-layout.adoc.vm similarity index 58% rename from src/site/asciidoc/manual/json-template-layout.adoc rename to src/site/asciidoc/manual/json-template-layout.adoc.vm index 1be3f5f..c2da984 100644 --- a/src/site/asciidoc/manual/json-template-layout.adoc +++ b/src/site/asciidoc/manual/json-template-layout.adoc.vm @@ -17,33 +17,33 @@ = JSON Template Layout Volkan Yazıcı -JsonTemplateLayout is a customizable, efficient, and garbage-free JSON -emitting layout. It encodes LogEvents according to the structure described +`JsonTemplateLayout` is a customizable, efficient, and garbage-free JSON +emitting layout. It encodes ``LogEvent``s according to the structure described by the JSON template provided. In a nutshell, it shines with its -* Customizable JSON structure (see eventTemplate[Uri] and - stackTraceElementTemplate[Uri] parameters) +* Customizable JSON structure (see `eventTemplate[Uri]` and + `stackTraceElementTemplate[Uri]` parameters) -* Customizable timestamp formatting (see timestamp parameter) +* Customizable timestamp formatting (see `timestamp` parameter) [#usage] == Usage -Adding log4j-layout-json-template artifact to your list of dependencies is -enough to enable access to JsonTemplateLayout in your Log4j configuration: +Adding `log4j-layout-json-template` artifact to your list of dependencies is +enough to enable access to `JsonTemplateLayout` in your Log4j configuration: [source,xml] org.apache.logging.log4j log4j-layout-json-template -${log4j.version} +${Log4jReleaseVersion} For instance, given the following JSON template modelling the https://github.com/logstash/log4j-jsonevent-layout[the official Logstash -JSONEventLayoutV1] (accessible via classpath:LogstashJsonEventLayoutV1.json) +`JSONEventLayoutV1`] (accessible via `classpath:LogstashJsonEventLayoutV1.json`) [source,json] @@ -107,14 +107,14 @@ https://github.com/logstash/log4j-jsonevent-layout[the official Logstash } -in combination with the below log4j2.xml configuration: +in combination with the below `log4j2.xml` configuration: [source,xml] -or with the below log4j2.properties configuration: +or with the below `log4j2.properties` configuration: [source,ini] @@ -122,7 +122,7 @@ appender.console.json.type = JsonTemplateLayout appender.console.json.eventTemplateUri = classpath:LogstashJsonEventLayoutV1.json -JsonTemplateLayout emits JSON strings as follows: +`JsonTemplateLayout` emits JSON strings as follows: [source,json] @@ -149,9 +149,9 @@ appender.console.json.eventTemplateUri = classpath:LogstashJsonEventLayoutV1.jso [#layout-config] == Layout Configuration -JsonTemplateLayout is configured with the following parameters: +`JsonTemplateLayout` is configured with the following parameters: -.JsonTemplateLayout parameters +.`JsonTemplateLayout` parameters [cols="1m,1m,4"] |=== | Parameter Name @@ -160,29 +160,29 @@ appender.console.json.eventTemplateUri = classpath:LogstashJsonEventLayoutV1.jso | charset | Charset -| Charset used for String encoding +| `Charset` used for `String` encoding | locationInfoEnabled | boolean -| toggles access to the LogEvent source; file name, line number, etc. - (defaults to false set by log4j.layout.jsonTemplate.locationInfoEnabled +| toggles access to the `LogEvent` source; file name, line number, etc. + (defaults to `false` set by `log4j.layout.jsonTemplate.locationInfoEnabled` property) | stackTraceEnabled | boolean -| toggles access to the stack traces (defaults to true set by - log4j.layout.jsonTemplate.stackTraceEnabled property) +| toggles access to the stack traces (defaults to `true` set by + `log4j.layout.jsonTemplate.stackTraceEnabled` property) | eventTemplate | String -| inline JSON template for rendering LogEvents (has priority over - eventTemplateUri, defaults to null set by - log4j.layout.jsonTemplate.eventTemplate property) +| inline JSON template for rendering ``LogEvent``s (has priority over + `eventTemplateUri`, defaults to `null` set by + `log4j.layout.jsonTemplate.eventTemplate` property) | eventTemplateUri | String -| URI pointing to the JSON template for rendering LogEvents (defaults to - classpath:EcsLa
[logging-log4j2] 01/02: Enable AsciiDoc support in maven-site-plugin.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit c08496b7cbb789c9af59f8f2d9fd4c3ab9f2ec1a Author: Volkan Yazıcı AuthorDate: Tue Aug 25 09:21:37 2020 +0200 Enable AsciiDoc support in maven-site-plugin. --- pom.xml | 15 --- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index ed6921d..d232bde 100644 --- a/pom.xml +++ b/pom.xml @@ -225,6 +225,7 @@ 1.5 +1.5.6 1.5 ${project.build.outputDirectory}/META-INF/MANIFEST.MF 1.8 @@ -1188,9 +1189,9 @@ ${site.plugin.version} -org.apache.maven.wagon -wagon-ssh -3.1.0 +org.asciidoctor +asciidoctor-maven-plugin +${asciidoc.plugin.version} @@ -1202,6 +1203,14 @@ navigation.xml,changes.xml + + + + ${Log4jReleaseVersion} + ${Log4jReleaseManager} + ${Log4jReleaseKey} + +
[logging-log4j2] branch release-2.x updated (1779fbe -> 20d5463)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 1779fbe [LOG4J2-2653] Migrate pattern tests to JUnit 5 new c08496b Enable AsciiDoc support in maven-site-plugin. new 20d5463 #335 Migrate JsonTemplateLayout manual from Xdoc to AsciiDoc. The 2 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: pom.xml| 15 +- ...te-layout.adoc => json-template-layout.adoc.vm} | 344 ++--- src/site/xdoc/manual/json-template-layout.xml.vm | 1526 3 files changed, 189 insertions(+), 1696 deletions(-) rename src/site/asciidoc/manual/{json-template-layout.adoc => json-template-layout.adoc.vm} (58%) delete mode 100644 src/site/xdoc/manual/json-template-layout.xml.vm
[logging-log4j2] branch master updated: #335 Add Velocity support to JsonTemplateLayout manual.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 05288f4 #335 Add Velocity support to JsonTemplateLayout manual. 05288f4 is described below commit 05288f49bd6d5c0a6fb3ab9f7cbbc11ebef2ada7 Author: Volkan Yazıcı AuthorDate: Tue Aug 25 09:36:56 2020 +0200 #335 Add Velocity support to JsonTemplateLayout manual. --- .../{json-template-layout.adoc => json-template-layout.adoc.vm} | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/site/asciidoc/manual/json-template-layout.adoc b/src/site/asciidoc/manual/json-template-layout.adoc.vm similarity index 99% rename from src/site/asciidoc/manual/json-template-layout.adoc rename to src/site/asciidoc/manual/json-template-layout.adoc.vm index f520796..c2da984 100644 --- a/src/site/asciidoc/manual/json-template-layout.adoc +++ b/src/site/asciidoc/manual/json-template-layout.adoc.vm @@ -37,7 +37,7 @@ enough to enable access to `JsonTemplateLayout` in your Log4j configuration: org.apache.logging.log4j log4j-layout-json-template -${log4j.version} +${Log4jReleaseVersion} @@ -1181,9 +1181,9 @@ alternatives. [#faq-lookups] === Are lookups supported in templates? -Yes, link:lookups.html[lookups] (e.g., `${java:version}`, `${env:USER}`, -`${date:MM-dd-}`) are supported in string literals of templates. Though note -that they are not garbage-free. +Yes, link:lookups.html[lookups] (e.g., `${dollar}{java:version}`, +`${dollar}{env:USER}`, `${dollar}{date:MM-dd-}`) are supported in string +literals of templates. Though note that they are not garbage-free. [#faq-garbage-free] === Is `JsonTemplateLayout` garbage-free?
[logging-log4j2] branch release-2.x updated: #335 Fix forgotten renaming in revapi.json.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 8fea321 #335 Fix forgotten renaming in revapi.json. 8fea321 is described below commit 8fea321a302aee65ac58960194f82a2080eb743b Author: Volkan Yazıcı AuthorDate: Tue Aug 25 11:36:04 2020 +0200 #335 Fix forgotten renaming in revapi.json. --- log4j-layout-template-json/revapi.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/log4j-layout-template-json/revapi.json b/log4j-layout-template-json/revapi.json index cf1bfdf..65b729f 100644 --- a/log4j-layout-template-json/revapi.json +++ b/log4j-layout-template-json/revapi.json @@ -5,9 +5,9 @@ "filter": { "classes": { "exclude": [ - "org\\.apache\\.logging\\.log4j\\.layout\\.json\\.template\\.resolver\\.TemplateResolverConfig", - "org\\.apache\\.logging\\.log4j\\.layout\\.json\\.template\\.resolver\\.TemplateResolverContext", - "org\\.apache\\.logging\\.log4j\\.layout\\.json\\.template\\.resolver\\.TemplateResolverFactory" + "org\\.apache\\.logging\\.log4j\\.layout\\.template\\.json\\.resolver\\.TemplateResolverConfig", + "org\\.apache\\.logging\\.log4j\\.layout\\.template\\.json\\.resolver\\.TemplateResolverContext", + "org\\.apache\\.logging\\.log4j\\.layout\\.template\\.json\\.resolver\\.TemplateResolverFactory" ] } }
[logging-log4j2] branch release-2.x updated: Upgrade Maven wrapper.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 9706741 Upgrade Maven wrapper. 9706741 is described below commit 970674164de2a0e1e84b2408a24fe98562a8dfe8 Author: Volkan Yazıcı AuthorDate: Tue Aug 25 11:09:20 2020 +0200 Upgrade Maven wrapper. --- .mvn/wrapper/MavenWrapperDownloader.java | 117 +++ .mvn/wrapper/maven-wrapper.jar | Bin 49519 -> 50710 bytes .mvn/wrapper/maven-wrapper.properties| 3 +- mvnw | 156 +++ mvnw.cmd | 54 +-- 5 files changed, 279 insertions(+), 51 deletions(-) diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 000..b901097 --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-present the original author or authors. + * + * 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. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + +private static final String WRAPPER_VERSION = "0.5.6"; +/** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ +private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/; ++ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + +/** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ +private static final String MAVEN_WRAPPER_PROPERTIES_PATH = +".mvn/wrapper/maven-wrapper.properties"; + +/** + * Path where the maven-wrapper.jar will be saved to. + */ +private static final String MAVEN_WRAPPER_JAR_PATH = +".mvn/wrapper/maven-wrapper.jar"; + +/** + * Name of the property which should be used to override the default download url for the wrapper. + */ +private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + +public static void main(String args[]) { +System.out.println("- Downloader started"); +File baseDirectory = new File(args[0]); +System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + +// If the maven-wrapper.properties exists, read it and check if it contains a custom +// wrapperUrl parameter. +File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); +String url = DEFAULT_DOWNLOAD_URL; +if(mavenWrapperPropertyFile.exists()) { +FileInputStream mavenWrapperPropertyFileInputStream = null; +try { +mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); +Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); +url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); +} catch (IOException e) { +System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); +} finally { +try { +if(mavenWrapperPropertyFileInputStream != null) { +mavenWrapperPropertyFileInputStream.close(); +} +} catch (IOException e) { +// Ignore ... +} +} +} +System.out.println("- Downloading from: " + url); + +File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); +if(!outputFile.getParentFile().exists()) { +if(!outputFile.getParentFile().mkdirs()) { +System.out.println( +"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); +} +} +System.out.println(
[logging-log4j2] branch release-2.x updated: Try improving RollingAppenderRestartTest to alleviate test report failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 4867187 Try improving RollingAppenderRestartTest to alleviate test report failures. 4867187 is described below commit 48671873a340e73a0c2e2920fd8d4b07494bebaa Author: Volkan Yazıcı AuthorDate: Tue Aug 25 14:24:52 2020 +0200 Try improving RollingAppenderRestartTest to alleviate test report failures. --- .../rolling/RollingAppenderRestartTest.java| 48 +++--- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java index 80474b6..bf8b39b 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderRestartTest.java @@ -16,21 +16,27 @@ */ package org.apache.logging.log4j.core.appender.rolling; +import org.apache.commons.io.file.PathUtils; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.junit.LoggerContextRule; import org.hamcrest.Matcher; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import java.io.File; +import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.FileTime; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.Arrays; import static org.apache.logging.log4j.hamcrest.Descriptors.that; import static org.apache.logging.log4j.hamcrest.FileMatchers.hasName; @@ -38,37 +44,49 @@ import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.hasItemInArray; import static org.junit.Assert.assertTrue; -/** - * - */ public class RollingAppenderRestartTest { private static final String CONFIG = "log4j-rolling-restart.xml"; -private static final String DIR = "target/rolling-restart"; -private final LoggerContextRule loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); +// Note that both paths are hardcoded in the configuration! +private static final Path DIR = Paths.get("target/rolling-restart"); +private static final Path FILE = DIR.resolve("test.log"); + +private final LoggerContextRule loggerContextRule = +LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); @Rule -public RuleChain chain = loggerContextRule.withCleanFoldersRule(false, true, 5, DIR); +public RuleChain chain = +loggerContextRule.withCleanFoldersRule( +false, true, 5, DIR.toAbsolutePath().toString()); @BeforeClass public static void setup() throws Exception { -File file = new File("target/rolling-restart/test.log"); -Files.createDirectories(file.toPath().getParent()); -Files.write(file.toPath(), "Hello, world".getBytes(), StandardOpenOption.CREATE); +tearDown(); +Files.createDirectories(DIR); +Files.write(FILE, "Hello, world".getBytes(), StandardOpenOption.CREATE); FileTime newTime = FileTime.from(Instant.now().minus(2, ChronoUnit.DAYS)); -Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class).setTimes(newTime, newTime, newTime); +Files +.getFileAttributeView(FILE, BasicFileAttributeView.class) +.setTimes(newTime, newTime, newTime); +} + +@AfterClass +public static void tearDown() throws IOException { +if (DIR.toFile().exists()) { +PathUtils.deleteDirectory(DIR); +} } @Test public void testAppender() throws Exception { final Logger logger = loggerContextRule.getLogger(); logger.info("This is test message number 1"); - -final File dir = new File(DIR); - final Matcher hasGzippedFile = hasItemInArray(that(hasName(that(endsWith(".gz"); -final File[] files = dir.listFiles(); -assertTrue("No gzipped files found", hasGzippedFile.matches(files)); +final File[] files = DIR.toFile().listFiles(); +assertTrue( +"was expecting files with '.gz' suffix, found: " + Arrays.toString(files), +hasGzippedFile.matches(files)); } + }
[logging-log4j2] branch release-2.x updated: Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 0c6248d Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures. 0c6248d is described below commit 0c6248dff3b702e36d7de9b0d3f3b3349b3636a5 Author: Volkan Yazıcı AuthorDate: Tue Aug 25 16:22:40 2020 +0200 Try improving RollingDirectSizeTimeNewDirectoryTest to alleviate test report failures. --- .../RollingDirectSizeTimeNewDirectoryTest.java | 93 +- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java index 9978aa8..9afbfa9 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingDirectSizeTimeNewDirectoryTest.java @@ -16,47 +16,39 @@ */ package org.apache.logging.log4j.core.appender.rolling; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.junit.LoggerContextRule; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.RuleChain; import java.io.File; import java.util.Arrays; -import java.util.List; +import java.util.Iterator; -import static java.util.Arrays.asList; -import static java.util.Collections.sort; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; -/** - * Tests - */ public class RollingDirectSizeTimeNewDirectoryTest { + private static final String CONFIG = "log4j-rolling-size-time-new-directory.xml"; +// Note that the path is hardcoded in the configuration! private static final String DIR = "target/rolling-size-time-new-directory"; -public static LoggerContextRule loggerContextRule = LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); +public static LoggerContextRule loggerContextRule = +LoggerContextRule.createShutdownTimeoutLoggerContextRule(CONFIG); @Rule public RuleChain chain = loggerContextRule.withCleanFoldersRule(DIR); -private Logger logger; - -@Before -public void setUp() throws Exception { -this.logger = loggerContextRule.getLogger(RollingDirectSizeTimeNewDirectoryTest.class.getName()); -} - - @Test public void streamClosedError() throws Exception { + +final Logger logger = + loggerContextRule.getLogger(RollingDirectSizeTimeNewDirectoryTest.class); + for (int i = 0; i < 1000; i++) { logger.info("nHq6p9kgfvWfjzDRYbZp"); } @@ -65,25 +57,52 @@ public class RollingDirectSizeTimeNewDirectoryTest { logger.info("nHq6p9kgfvWfjzDRYbZp"); } -File tempDirectoryAsFile = new File(DIR); -File[] loggingFolders = tempDirectoryAsFile.listFiles(); -assertNotNull(loggingFolders); -// Check if two folders were created -assertTrue("Not enough directories created", loggingFolders.length >= 2); -Arrays.sort(loggingFolders); -for (int i = 0; i < loggingFolders.length; ++i) { -File dir = loggingFolders[i]; -File[] files = dir.listFiles(); -assertTrue("No files in directory " + dir.toString(), files != null && files.length > 0); -if (i > 0 && i < loggingFolders.length - 1) { -if (files.length < 3) { -System.out.println("Only " + files.length + " files created in " + dir.toString()); -for (File logFile : files) { -System.out.println("File name: " + logFile.getName() + " size: " + logFile.length()); -} -fail(); +final File logDir = new File(DIR); +final File[] logFolders = logDir.listFiles(); +assertNotNull(logFolders); +Arrays.sort(logFolders); + +try { + +final int minExpectedLogFolderCount = 2; +assertTrue( +"was expecting at least " + minExpectedLogFolderCount + " folders, " + +"found " + logFolders.length, +logFolders.length >= minExpectedLogFolder
[logging-log4j2] branch master updated: Bump jctools-core from 1.2.1 to 3.1.0
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 1071514 Bump jctools-core from 1.2.1 to 3.1.0 1071514 is described below commit 1071514c4a7942574b48e5bcc1a78773a5efab8c Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> AuthorDate: Sat Aug 8 16:50:34 2020 + Bump jctools-core from 1.2.1 to 3.1.0 Bumps [jctools-core](https://github.com/JCTools/JCTools) from 1.2.1 to 3.1.0. - [Release notes](https://github.com/JCTools/JCTools/releases) - [Changelog](https://github.com/JCTools/JCTools/blob/master/RELEASE-NOTES.md) - [Commits](https://github.com/JCTools/JCTools/compare/v1.2.1...v3.1.0) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9f81156..c0b9721 100644 --- a/pom.xml +++ b/pom.xml @@ -241,7 +241,7 @@ 5.15.9 info -1.2.1 +3.1.0 4.13 5.6.2 3.5.5
[logging-log4j2] branch master updated: Bump org.apache.felix.framework from 5.6.10 to 6.0.3
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 4b9e3c2 Bump org.apache.felix.framework from 5.6.10 to 6.0.3 4b9e3c2 is described below commit 4b9e3c26980d2919d8cd88999a2ea6d6989f8ffc Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> AuthorDate: Mon Aug 24 04:02:26 2020 + Bump org.apache.felix.framework from 5.6.10 to 6.0.3 Bumps org.apache.felix.framework from 5.6.10 to 6.0.3. Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a8f278a..84dec4f 100644 --- a/pom.xml +++ b/pom.xml @@ -296,7 +296,7 @@ org.apache.felix org.apache.felix.framework -5.6.10 +6.0.3 org.apache.maven
[logging-log4j2] branch master updated (1071514 -> 2c7d137)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 1071514 Bump jctools-core from 1.2.1 to 3.1.0 add 2c7d137 Bump maven-pmd-plugin from 3.10.0 to 3.13.0 No new revisions were added by this update. Summary of changes: pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] branch master updated (4b9e3c2 -> 058024f)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 4b9e3c2 Bump org.apache.felix.framework from 5.6.10 to 6.0.3 add 058024f Bump jetty-util from 8.2.0.v20160908 to 9.4.31.v20200723 No new revisions were added by this update. Summary of changes: log4j-appserver/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] branch master updated: Don't ignore test failures at build.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new a051e53 Don't ignore test failures at build. a051e53 is described below commit a051e533f57b8e8e66ba8474f6873f6da1e868f5 Author: Volkan Yazıcı AuthorDate: Wed Aug 26 14:03:42 2020 +0200 Don't ignore test failures at build. --- .github/workflows/maven.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5647d10..f2ad5ba 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -44,7 +44,7 @@ jobs: - name: Build with Maven (Linux) if: runner.os == 'Linux' -run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify +run: ./mvnw -V -B -e -DtrimStackTrace=false -Dsurefire.rerunFailingTestsCount=2 --global-toolchains .github/workflows/maven-toolchains.xml verify - name: Publish Test Results (Linux) if: runner.os == 'Linux' @@ -60,7 +60,7 @@ jobs: - name: Build with Maven (Windows) if: runner.os == 'Windows' -run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" --global-toolchains ".github\workflows\maven-toolchains.xml" verify +run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dsurefire.rerunFailingTestsCount=2" --global-toolchains ".github\workflows\maven-toolchains.xml" verify - name: Publish Test Results (Windows) if: runner.os == 'Windows' @@ -76,7 +76,7 @@ jobs: - name: Build with Maven (MacOS) if: runner.os == 'macOS' -run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify +run: ./mvnw -V -B -e -DtrimStackTrace=false -Dsurefire.rerunFailingTestsCount=2 --global-toolchains .github/workflows/maven-toolchains.xml verify - name: Publish Test Results (MacOS) if: runner.os == 'macOS'
[logging-log4j2] branch release-2.x updated: Don't ignore test failures at build.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 1348cfb Don't ignore test failures at build. 1348cfb is described below commit 1348cfbc60a5a15e44321d9219dc881efe68feba Author: Volkan Yazıcı AuthorDate: Wed Aug 26 14:03:42 2020 +0200 Don't ignore test failures at build. --- .github/workflows/maven.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b99a32e..b207c3e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -44,7 +44,7 @@ jobs: - name: Build with Maven (Linux) if: runner.os == 'Linux' -run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify +run: ./mvnw -V -B -e -DtrimStackTrace=false -Dsurefire.rerunFailingTestsCount=2 --global-toolchains .github/workflows/maven-toolchains.xml verify - name: Publish Test Results (Linux) if: runner.os == 'Linux' @@ -60,7 +60,7 @@ jobs: - name: Build with Maven (Windows) if: runner.os == 'Windows' -run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" --global-toolchains ".github\workflows\maven-toolchains.xml" verify +run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dsurefire.rerunFailingTestsCount=2" --global-toolchains ".github\workflows\maven-toolchains.xml" verify - name: Publish Test Results (Windows) if: runner.os == 'Windows' @@ -76,7 +76,7 @@ jobs: - name: Build with Maven (MacOS) if: runner.os == 'macOS' -run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify +run: ./mvnw -V -B -e -DtrimStackTrace=false -Dsurefire.rerunFailingTestsCount=2 --global-toolchains .github/workflows/maven-toolchains.xml verify - name: Publish Test Results (MacOS) if: runner.os == 'macOS'
[logging-log4j2] branch release-2.x updated (1348cfb -> 704b16f)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. discard 1348cfb Don't ignore test failures at build. This update removed existing revisions from the reference, leaving the reference pointing at a previous point in the repository history. * -- * -- N refs/heads/release-2.x (704b16f) \ O -- O -- O (1348cfb) Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. No new revisions were added by this update. Summary of changes: .github/workflows/maven.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
[logging-log4j2] branch master updated (a051e53 -> 058024f)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. discard a051e53 Don't ignore test failures at build. This update removed existing revisions from the reference, leaving the reference pointing at a previous point in the repository history. * -- * -- N refs/heads/master (058024f) \ O -- O -- O (a051e53) Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. No new revisions were added by this update. Summary of changes: .github/workflows/maven.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
[logging-log4j2] branch release-2.x updated: Upload test reports in GitHub Actions.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new f2c311e Upload test reports in GitHub Actions. f2c311e is described below commit f2c311e691cbe468f0e27837b44e4ebc690256e5 Author: Volkan Yazıcı AuthorDate: Wed Aug 26 14:34:31 2020 +0200 Upload test reports in GitHub Actions. --- .github/workflows/maven.yml | 27 --- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b99a32e..325cf63 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -46,14 +46,6 @@ jobs: if: runner.os == 'Linux' run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify - - name: Publish Test Results (Linux) -if: runner.os == 'Linux' -uses: scacap/action-surefire-report@v1 -with: - github_token: ${{ secrets.GITHUB_TOKEN }} - check_name: 'Test Report (Linux)' - report_paths: '**/*-reports/TEST-*.xml' - - name: Inspect environment (Windows) if: runner.os == 'Windows' run: set java @@ -62,14 +54,6 @@ jobs: if: runner.os == 'Windows' run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" --global-toolchains ".github\workflows\maven-toolchains.xml" verify - - name: Publish Test Results (Windows) -if: runner.os == 'Windows' -uses: scacap/action-surefire-report@v1 -with: - github_token: ${{ secrets.GITHUB_TOKEN }} - check_name: 'Test Report (Windows)' - report_paths: '**/*-reports/TEST-*.xml' - - name: Inspect environment (MacOS) if: runner.os == 'macOS' run: env | grep '^JAVA' @@ -78,10 +62,15 @@ jobs: if: runner.os == 'macOS' run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify - - name: Publish Test Results (MacOS) -if: runner.os == 'macOS' + - name: Publish Test Results uses: scacap/action-surefire-report@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} - check_name: 'Test Report (MacOS)' + check_name: Test Report (${{ matrix.os }}) report_paths: '**/*-reports/TEST-*.xml' + + - name: Upload Test Reports +uses: actions/upload-artifact@v2 +with: + name: test-reports-${{ matrix.os }} + path: '**/*-reports'
[logging-log4j2] branch master updated: Update changes.xml.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new cdc6185 Update changes.xml. cdc6185 is described below commit cdc61855212b3939fc16d9ebe1b23a23413f50de Author: Volkan Yazıcı AuthorDate: Wed Aug 26 16:41:16 2020 +0200 Update changes.xml. --- src/changes/changes.xml | 12 1 file changed, 12 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 927c50c..d9e5910 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -31,6 +31,18 @@ - "remove" - Removed --> + +Update jetty-util from 8.2.0.v20160908 to 9.4.31.v20200723. + + +Update org.apache.felix.framework from 5.6.10 to 6.0.3. + + +Update commons-compress from 1.18 to 1.20. + + +Update Jackson from 2.11.1 to 2.11.2. + Add Redis Appender.
[logging-log4j2] 02/02: Add GitHub Actions CI support to release-2.x branch.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 45138174ea99f246a6223c0c9cdd2666714821f8 Author: Volkan Yazıcı AuthorDate: Thu Aug 20 15:58:49 2020 +0200 Add GitHub Actions CI support to release-2.x branch. --- .github/workflows/maven-toolchains.xml | 37 +++ .github/workflows/maven.yml| 87 ++ 2 files changed, 124 insertions(+) diff --git a/.github/workflows/maven-toolchains.xml b/.github/workflows/maven-toolchains.xml new file mode 100644 index 000..066a50f --- /dev/null +++ b/.github/workflows/maven-toolchains.xml @@ -0,0 +1,37 @@ + + + + +jdk + + 1.8 + + + ${env.JAVA_HOME_8_X64} + + + +jdk + + 11 + + + ${env.JAVA_HOME_11_X64} + + + diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 000..b99a32e --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,87 @@ +name: Maven + +on: [push] + +jobs: + build: + +runs-on: ${{ matrix.os }} + +strategy: + matrix: +os: [ubuntu-latest, windows-latest, macos-latest] + +steps: + + - name: Checkout repository +uses: actions/checkout@v2 + + - name: Setup Maven caching +uses: actions/cache@v2 +with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | +${{ runner.os }}-maven- + + - name: Setup JDK 11 +uses: actions/setup-java@v1 +with: + java-version: 11 + java-package: jdk + architecture: x64 + + - name: Setup JDK 8 +uses: actions/setup-java@v1 +with: + java-version: 8 + java-package: jdk + architecture: x64 + + - name: Inspect environment (Linux) +if: runner.os == 'Linux' +run: env | grep '^JAVA' + + - name: Build with Maven (Linux) +if: runner.os == 'Linux' +run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify + + - name: Publish Test Results (Linux) +if: runner.os == 'Linux' +uses: scacap/action-surefire-report@v1 +with: + github_token: ${{ secrets.GITHUB_TOKEN }} + check_name: 'Test Report (Linux)' + report_paths: '**/*-reports/TEST-*.xml' + + - name: Inspect environment (Windows) +if: runner.os == 'Windows' +run: set java + + - name: Build with Maven (Windows) +if: runner.os == 'Windows' +run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" --global-toolchains ".github\workflows\maven-toolchains.xml" verify + + - name: Publish Test Results (Windows) +if: runner.os == 'Windows' +uses: scacap/action-surefire-report@v1 +with: + github_token: ${{ secrets.GITHUB_TOKEN }} + check_name: 'Test Report (Windows)' + report_paths: '**/*-reports/TEST-*.xml' + + - name: Inspect environment (MacOS) +if: runner.os == 'macOS' +run: env | grep '^JAVA' + + - name: Build with Maven (MacOS) +if: runner.os == 'macOS' +run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify + + - name: Publish Test Results (MacOS) +if: runner.os == 'macOS' +uses: scacap/action-surefire-report@v1 +with: + github_token: ${{ secrets.GITHUB_TOKEN }} + check_name: 'Test Report (MacOS)' + report_paths: '**/*-reports/TEST-*.xml'
[logging-log4j2] branch release-2.x updated (736bcb5 -> 4513817)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 736bcb5 Add new articles new c11ed6f #335 Initial import of JsonTemplateLayout from LogstashLayout. new 4513817 Add GitHub Actions CI support to release-2.x branch. The 2 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: .../workflows}/maven-toolchains.xml|0 .github/workflows/maven.yml| 87 + .../org/apache/logging/log4j/util/Strings.java | 36 +- .../org/apache/logging/log4j/util/StringsTest.java | 19 + log4j-bom/pom.xml |6 + .../apache/logging/log4j/core/util/Throwables.java | 22 +- .../logging/log4j/core/GcFreeLoggingTestUtil.java | 70 +- .../logging/log4j/core/util/ThrowablesTest.java| 37 +- log4j-jpl/pom.xml | 12 - log4j-layout-json-template/pom.xml | 533 ++ log4j-layout-json-template/revapi.json | 16 + .../layout/json/template/JsonTemplateLayout.java | 688 +++ .../json/template/JsonTemplateLayoutDefaults.java | 213 +++ .../json/template/resolver/EndOfBatchResolver.java | 44 + .../resolver/EndOfBatchResolverFactory.java| 41 + .../json/template/resolver/EventResolver.java | 21 + .../template/resolver/EventResolverContext.java| 228 +++ .../template/resolver/EventResolverFactories.java | 65 + .../template/resolver/EventResolverFactory.java| 21 + .../resolver/ExceptionInternalResolverFactory.java | 68 + .../json/template/resolver/ExceptionResolver.java | 122 ++ .../resolver/ExceptionResolverFactory.java | 43 + .../resolver/ExceptionRootCauseResolver.java | 127 ++ .../ExceptionRootCauseResolverFactory.java | 41 + .../json/template/resolver/LevelResolver.java | 176 ++ .../template/resolver/LevelResolverFactory.java| 41 + .../json/template/resolver/LoggerResolver.java | 92 + .../template/resolver/LoggerResolverFactory.java | 41 + .../json/template/resolver/MainMapResolver.java| 90 + .../template/resolver/MainMapResolverFactory.java | 41 + .../layout/json/template/resolver/MapResolver.java | 91 + .../json/template/resolver/MapResolverFactory.java | 41 + .../json/template/resolver/MarkerResolver.java | 86 + .../template/resolver/MarkerResolverFactory.java | 41 + .../json/template/resolver/MessageResolver.java| 223 +++ .../template/resolver/MessageResolverFactory.java | 41 + .../json/template/resolver/PatternResolver.java| 87 + .../template/resolver/PatternResolverFactory.java | 41 + .../json/template/resolver/SourceResolver.java | 148 ++ .../template/resolver/SourceResolverFactory.java | 41 + .../resolver/StackTraceElementObjectResolver.java | 92 + .../StackTraceElementObjectResolverContext.java| 93 + .../StackTraceElementObjectResolverFactories.java | 39 + .../StackTraceElementObjectResolverFactory.java| 43 + .../resolver/StackTraceObjectResolver.java | 54 + .../json/template/resolver/StackTraceResolver.java | 19 + .../resolver/StackTraceStringResolver.java | 51 + .../json/template/resolver/TemplateResolver.java | 42 + .../template/resolver/TemplateResolverConfig.java | 29 + .../template/resolver/TemplateResolverContext.java | 34 + .../template/resolver/TemplateResolverFactory.java | 25 + .../json/template/resolver/TemplateResolvers.java | 414 + .../resolver/ThreadContextDataResolver.java| 357 .../resolver/ThreadContextDataResolverFactory.java | 43 + .../resolver/ThreadContextStackResolver.java | 107 ++ .../ThreadContextStackResolverFactory.java | 43 + .../json/template/resolver/ThreadResolver.java | 90 + .../template/resolver/ThreadResolverFactory.java | 41 + .../json/template/resolver/TimestampResolver.java | 505 ++ .../resolver/TimestampResolverFactory.java | 41 + .../layout/json/template/util/DummyRecycler.java | 37 + .../json/template/util/DummyRecyclerFactory.java | 39 + .../layout/json/template/util/JsonReader.java | 447 + .../layout/json/template/util/JsonWriter.java | 889 + .../layout/json/template/util/MapAccessor.java | 139 ++ .../json/template/util/QueueingRecycler.java | 61 + .../template/util/QueueingRecyclerFactory.java | 40 + .../log4j/layout/json/template/util/Recycler.java | 25 + .../json/template/util/RecyclerFactories.java | 205 +++ .../layout/json/template/util/RecyclerFactory.java | 31 + .../json/template/util/String
[logging-log4j2] branch master updated (22c1f39 -> 86f3653)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 22c1f39 LOG4J2-2847 Extend Log4j-config.xsd (#360) new 21df99b #335 Fix code typo in EnhancedGelf.json. new 86f3653 #335 Small fixes in the manual. The 2 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: .../src/main/resources/EnhancedGelf.json | 5 ++--- src/site/asciidoc/manual/json-template-layout.adoc | 9 - 2 files changed, 6 insertions(+), 8 deletions(-)
[logging-log4j2] 01/02: #335 Fix code typo in EnhancedGelf.json.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 21df99bf496ef043c1d78efd2978ce4c1f8005da Author: Volkan Yazıcı AuthorDate: Thu Aug 20 15:51:54 2020 +0200 #335 Fix code typo in EnhancedGelf.json. --- .../src/main/resources/EnhancedGelf.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/src/main/resources/EnhancedGelf.json b/log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/src/main/resources/EnhancedGelf.json index 994b0c7..feaf3e0 100644 --- a/log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/src/main/resources/EnhancedGelf.json +++ b/log4j-spring-cloud-config/log4j-spring-cloud-config-samples/log4j-spring-cloud-config-sample-application/src/main/resources/EnhancedGelf.json @@ -6,9 +6,8 @@ "stringified": true }, "full_message": { -"$resolver": "message", -"pattern": "[%t] %-5p %X{requestId, sessionId, loginId, userId, ipAddress, corpAcctNumber} %C{1.}.%M:%L - %m", -"stringified": true +"$resolver": "pattern", +"pattern": "[%t] %-5p %X{requestId, sessionId, loginId, userId, ipAddress, corpAcctNumber} %C{1.}.%M:%L - %m" }, "timestamp": { "$resolver": "timestamp",
[logging-log4j2] 02/02: #335 Small fixes in the manual.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 86f36534cda6a1415aa5e3cf3f9832aebc9428f2 Author: Volkan Yazıcı AuthorDate: Thu Aug 20 15:52:16 2020 +0200 #335 Small fixes in the manual. --- src/site/asciidoc/manual/json-template-layout.adoc | 9 - 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/site/asciidoc/manual/json-template-layout.adoc b/src/site/asciidoc/manual/json-template-layout.adoc index 92ec635..f520796 100644 --- a/src/site/asciidoc/manual/json-template-layout.adoc +++ b/src/site/asciidoc/manual/json-template-layout.adoc @@ -563,7 +563,7 @@ Resolve the logger's fully qualified class name: } -| main: +| main a| [source] @@ -1126,7 +1126,7 @@ alternatives. | None | None -| Full schema customization? +| Schema customization? | ✓ | ✕ | ✕ @@ -1168,7 +1168,7 @@ alternatives. | ✕ | ✕ -| Additional fields? +| Additional field support? | ✓ | ✓ | ✓ @@ -1202,8 +1202,7 @@ enabled. Take into account the following caveats: garbage-free except for certain types (e.g., `BigDecimal`, `BigInteger`, ``Collection``s with the exception of `List`). -* link:lookups.html[Lookups] (that is, `${...}` variables, excluding - `${json:...}` ones) are not garbage-free. +* link:lookups.html[Lookups] (that is, `${...}` variables) are not garbage-free. Don't forget to checkout link:#event-template-resolvers[the notes on garbage footprint of resolvers] you employ in templates.
[logging-log4j2] branch release-2.x updated: Delete unused BasicLayout.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 70ce318 Delete unused BasicLayout. 70ce318 is described below commit 70ce3183f3c811e3cde2052b60587e8a96d0a8ee Author: Volkan Yazici AuthorDate: Wed Sep 23 15:56:14 2020 +0200 Delete unused BasicLayout. --- .../logging/log4j/test/layout/BasicLayout.java | 57 -- 1 file changed, 57 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java deleted file mode 100644 index 7c13ff9..000 --- a/log4j-core/src/test/java/org/apache/logging/log4j/test/layout/BasicLayout.java +++ /dev/null @@ -1,57 +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.logging.log4j.test.layout; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -import org.apache.logging.log4j.core.Core; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; -import org.apache.logging.log4j.core.layout.AbstractStringLayout; -import org.apache.logging.log4j.util.Strings; - -/** - * - */ -@Plugin(name = "BasicLayout", category = Core.CATEGORY_NAME, elementType = "layout", printObject = true) -public class BasicLayout extends AbstractStringLayout { - -private static final String HEADER = "Header" + Strings.LINE_SEPARATOR; - -public BasicLayout(final Charset charset) { -super(charset); -} - -@Override -public byte[] getHeader() { -return getBytes(HEADER); -} - -@Override -public String toSerializable(final LogEvent event) { -return event.getMessage().getFormattedMessage() + Strings.LINE_SEPARATOR; -} - -/** - */ -@PluginFactory -public static BasicLayout createLayout() { -return new BasicLayout(StandardCharsets.UTF_8); -} -}
[logging-log4j2] branch release-2.x updated (b68b299 -> 751cebd)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. discard b68b299 LOG4J2-620 ReconfigurationDeadlockTest rewrite to prevent spurious failures. new 751cebd LOG4J2-620 ReconfigurationDeadlockTest rewrite to prevent spurious failures. This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (b68b299) \ N -- N -- N refs/heads/release-2.x (751cebd) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 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/config/ReconfigurationDeadlockTest.java | 61 +++- .../log4j/test/SomethingThatUsesLogging.java | 36 - .../log4j/test/appender/DeadlockAppender.java | 85 -- .../log4j/test/appender/UsesLoggingAppender.java | 67 - .../test/resources/reconfiguration-deadlock.xml| 25 +++ 5 files changed, 71 insertions(+), 203 deletions(-) delete mode 100644 log4j-core/src/test/java/org/apache/logging/log4j/test/SomethingThatUsesLogging.java delete mode 100644 log4j-core/src/test/java/org/apache/logging/log4j/test/appender/DeadlockAppender.java delete mode 100644 log4j-core/src/test/java/org/apache/logging/log4j/test/appender/UsesLoggingAppender.java
[logging-log4j2] 01/01: LOG4J2-620 ReconfigurationDeadlockTest rewrite to prevent spurious failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 751cebdb59e1046e080ee96a21233602355c65de Author: Volkan Yazici AuthorDate: Wed Sep 23 12:13:40 2020 +0200 LOG4J2-620 ReconfigurationDeadlockTest rewrite to prevent spurious failures. --- .../core/config/ReconfigurationDeadlockTest.java | 209 + .../log4j/test/SomethingThatUsesLogging.java | 36 .../log4j/test/appender/DeadlockAppender.java | 85 - .../log4j/test/appender/UsesLoggingAppender.java | 67 --- .../test/resources/reconfiguration-deadlock.xml| 25 ++- 5 files changed, 143 insertions(+), 279 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationDeadlockTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationDeadlockTest.java index 5a6d5a2..91a8673 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationDeadlockTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationDeadlockTest.java @@ -16,107 +16,162 @@ */ package org.apache.logging.log4j.core.config; -import java.io.File; - 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.Core; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; import org.apache.logging.log4j.junit.LoggerContextSource; -import org.apache.logging.log4j.message.ThreadDumpMessage; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.RepeatedTest; +import java.io.File; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +/** + * Performs reconfiguration whilst logging. + * + * @see https://issues.apache.org/jira/browse/LOG4J2-620;>LOG4J2-620 + * @see TestAppender + */ @LoggerContextSource("reconfiguration-deadlock.xml") public class ReconfigurationDeadlockTest { -private static final int THREAD_COUNT = 5; -private static final boolean[] finished = new boolean[THREAD_COUNT]; -private static LoggerThread[] threads = new LoggerThread[THREAD_COUNT]; - -@Test -public void testReconfig() throws InterruptedException { +private static final int WORKER_COUNT = 100; -final Updater updater = new Updater(); -for (int i = 0; i < THREAD_COUNT; ++i) { -threads[i] = new LoggerThread(i); -threads[i].setDaemon(true); -} -for (int i = 0; i < THREAD_COUNT; ++i) { +private ExecutorService executor; -threads[i].start(); -} -updater.setDaemon(true); -updater.start(); -Thread.sleep(100); -boolean stillWaiting = true; -for (int i = 0; i < 200; ++i) { -int index = 0; -for (; index < THREAD_COUNT; ++index) { -if (!finished[index]) { -break; -} -} -if (index == THREAD_COUNT) { -stillWaiting = false; -break; -} -Thread.sleep(100); -} -updater.shutdown = true; -if (stillWaiting) { -final ThreadDumpMessage message = new ThreadDumpMessage("Waiting"); -System.err.print(message.getFormattedMessage()); -} -for (int i = 0; i < THREAD_COUNT; ++i) { -if (threads[i].isAlive()) { -threads[i].interrupt(); -} -} -assertFalse(stillWaiting, "loggerThread didn't finish"); +@BeforeEach +public void startExecutor() { +executor = Executors.newFixedThreadPool(WORKER_COUNT); +} +@AfterEach +public void stopExecutor() throws InterruptedException { +executor.shutdownNow(); +final boolean terminated = executor.awaitTermination(30, TimeUnit.SEC
[logging-log4j2] branch release-2.x updated: Workarounds for Windows-specific "file being used by another process" failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 933ba9a Workarounds for Windows-specific "file being used by another process" failures. 933ba9a is described below commit 933ba9ae4a023643e5186a22faed47bab4f5498f Author: Volkan Yazici AuthorDate: Tue Sep 22 21:49:52 2020 +0200 Workarounds for Windows-specific "file being used by another process" failures. --- .github/workflows/maven.yml | 2 +- .../org/apache/logging/log4j/junit/AbstractFileCleaner.java | 5 - .../org/apache/logging/log4j/junit/CleanUpDirectories.java | 6 -- .../java/org/apache/logging/log4j/junit/CleanUpFiles.java | 6 -- .../log4j/core/appender/RandomAccessFileManagerTest.java| 13 ++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 325cf63..3642f3a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -52,7 +52,7 @@ jobs: - name: Build with Maven (Windows) if: runner.os == 'Windows' -run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" --global-toolchains ".github\workflows\maven-toolchains.xml" verify +run: ./mvnw -V -B -e "-DtrimStackTrace=false" "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" "-Dlog4j2.junit.fileCleanerSleepPeriodMillis=1000" --global-toolchains ".github\workflows\maven-toolchains.xml" verify - name: Inspect environment (MacOS) if: runner.os == 'macOS' diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java index c5d2bc4..ce57b80 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java @@ -34,8 +34,11 @@ import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.fail; abstract class AbstractFileCleaner implements BeforeEachCallback, AfterEachCallback { + private static final int MAX_TRIES = Integer.getInteger("log4j2.junit.fileCleanerMaxTries", 10); +private static final int SLEEP_PERIOD_MILLIS = Integer.getInteger("log4j2.junit.fileCleanerSleepPeriodMillis", 200); + @Override public void beforeEach(final ExtensionContext context) throws Exception { clean(context); @@ -64,7 +67,7 @@ abstract class AbstractFileCleaner implements BeforeEachCallback, AfterEachCallb failures.put(path, e); } try { -TimeUnit.MILLISECONDS.sleep(200); +TimeUnit.MILLISECONDS.sleep(SLEEP_PERIOD_MILLIS); } catch (final InterruptedException ignored) { failures.put(path, new InterruptedIOException()); Thread.currentThread().interrupt(); diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java index 6c398e6..151bb85 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java @@ -28,9 +28,11 @@ import java.lang.annotation.Target; /** * JUnit extension to automatically clean up a list of directories and their contents before and after test execution. - * This will automatically retry deletion up to 10 times per file while pausing a short duration each time. - * This can be overridden with the system property {@code log4j2.junit.fileCleanerMaxTries}. + * This will automatically retry deletion up to 10 times per file while pausing for 200ms each time. + * These can be overridden with system properties {@code log4j2.junit.fileCleanerMaxTries} and + * {@code log4j2.junit.fileCleanerSleepPeriodMillis}. * + * @see DirectoryCleaner * @see CleanUpFiles * @since 2.14.0 */ diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java index a3b9ca6..e00ca42 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java @@ -28,9 +28,11 @@ import java.lang.annotation.Target; /** * JUnit extension to automatically clean up a list of files before and after test
[logging-log4j2] branch release-2.x updated: Workarounds for Windows-specific "file being used by another process" failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 933ba9a Workarounds for Windows-specific "file being used by another process" failures. 933ba9a is described below commit 933ba9ae4a023643e5186a22faed47bab4f5498f Author: Volkan Yazici AuthorDate: Tue Sep 22 21:49:52 2020 +0200 Workarounds for Windows-specific "file being used by another process" failures. --- .github/workflows/maven.yml | 2 +- .../org/apache/logging/log4j/junit/AbstractFileCleaner.java | 5 - .../org/apache/logging/log4j/junit/CleanUpDirectories.java | 6 -- .../java/org/apache/logging/log4j/junit/CleanUpFiles.java | 6 -- .../log4j/core/appender/RandomAccessFileManagerTest.java| 13 ++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 325cf63..3642f3a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -52,7 +52,7 @@ jobs: - name: Build with Maven (Windows) if: runner.os == 'Windows' -run: ./mvnw -V -B -e -DtrimStackTrace=false "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" --global-toolchains ".github\workflows\maven-toolchains.xml" verify +run: ./mvnw -V -B -e "-DtrimStackTrace=false" "-Dmaven.test.failure.ignore=true" "-Dsurefire.rerunFailingTestsCount=1" "-Dlog4j2.junit.fileCleanerSleepPeriodMillis=1000" --global-toolchains ".github\workflows\maven-toolchains.xml" verify - name: Inspect environment (MacOS) if: runner.os == 'macOS' diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java index c5d2bc4..ce57b80 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/AbstractFileCleaner.java @@ -34,8 +34,11 @@ import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.fail; abstract class AbstractFileCleaner implements BeforeEachCallback, AfterEachCallback { + private static final int MAX_TRIES = Integer.getInteger("log4j2.junit.fileCleanerMaxTries", 10); +private static final int SLEEP_PERIOD_MILLIS = Integer.getInteger("log4j2.junit.fileCleanerSleepPeriodMillis", 200); + @Override public void beforeEach(final ExtensionContext context) throws Exception { clean(context); @@ -64,7 +67,7 @@ abstract class AbstractFileCleaner implements BeforeEachCallback, AfterEachCallb failures.put(path, e); } try { -TimeUnit.MILLISECONDS.sleep(200); +TimeUnit.MILLISECONDS.sleep(SLEEP_PERIOD_MILLIS); } catch (final InterruptedException ignored) { failures.put(path, new InterruptedIOException()); Thread.currentThread().interrupt(); diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java index 6c398e6..151bb85 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpDirectories.java @@ -28,9 +28,11 @@ import java.lang.annotation.Target; /** * JUnit extension to automatically clean up a list of directories and their contents before and after test execution. - * This will automatically retry deletion up to 10 times per file while pausing a short duration each time. - * This can be overridden with the system property {@code log4j2.junit.fileCleanerMaxTries}. + * This will automatically retry deletion up to 10 times per file while pausing for 200ms each time. + * These can be overridden with system properties {@code log4j2.junit.fileCleanerMaxTries} and + * {@code log4j2.junit.fileCleanerSleepPeriodMillis}. * + * @see DirectoryCleaner * @see CleanUpFiles * @since 2.14.0 */ diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java index a3b9ca6..e00ca42 100644 --- a/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java +++ b/log4j-api/src/test/java/org/apache/logging/log4j/junit/CleanUpFiles.java @@ -28,9 +28,11 @@ import java.lang.annotation.Target; /** * JUnit extension to automatically clean up a list of files before and after test
[logging-log4j2] branch release-2.x updated: LOG4J2-620 ReconfigurationDeadlockTest rewrite to prevent spurious failures.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new b68b299 LOG4J2-620 ReconfigurationDeadlockTest rewrite to prevent spurious failures. b68b299 is described below commit b68b29986115da7f487e7ee825e11ef95e3366a9 Author: Volkan Yazici AuthorDate: Wed Sep 23 12:13:40 2020 +0200 LOG4J2-620 ReconfigurationDeadlockTest rewrite to prevent spurious failures. --- .../core/config/ReconfigurationDeadlockTest.java | 160 ++--- 1 file changed, 78 insertions(+), 82 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationDeadlockTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationDeadlockTest.java index 5a6d5a2..0431669 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationDeadlockTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ReconfigurationDeadlockTest.java @@ -16,107 +16,103 @@ */ package org.apache.logging.log4j.core.config; -import java.io.File; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.junit.LoggerContextSource; -import org.apache.logging.log4j.message.ThreadDumpMessage; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.RepeatedTest; +import java.io.File; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +/** + * Performs reconfiguration whilst logging. + * + * @see https://issues.apache.org/jira/browse/LOG4J2-620;>LOG4J2-620 + * @see org.apache.logging.log4j.test.appender.UsesLoggingAppender + */ @LoggerContextSource("reconfiguration-deadlock.xml") public class ReconfigurationDeadlockTest { -private static final int THREAD_COUNT = 5; -private static final boolean[] finished = new boolean[THREAD_COUNT]; -private static LoggerThread[] threads = new LoggerThread[THREAD_COUNT]; +private static final int WORKER_COUNT = 100; -@Test -public void testReconfig() throws InterruptedException { +private ExecutorService executor; -final Updater updater = new Updater(); -for (int i = 0; i < THREAD_COUNT; ++i) { -threads[i] = new LoggerThread(i); -threads[i].setDaemon(true); -} -for (int i = 0; i < THREAD_COUNT; ++i) { - -threads[i].start(); -} -updater.setDaemon(true); -updater.start(); -Thread.sleep(100); -boolean stillWaiting = true; -for (int i = 0; i < 200; ++i) { -int index = 0; -for (; index < THREAD_COUNT; ++index) { -if (!finished[index]) { -break; -} -} -if (index == THREAD_COUNT) { -stillWaiting = false; -break; -} -Thread.sleep(100); -} -updater.shutdown = true; -if (stillWaiting) { -final ThreadDumpMessage message = new ThreadDumpMessage("Waiting"); -System.err.print(message.getFormattedMessage()); -} -for (int i = 0; i < THREAD_COUNT; ++i) { -if (threads[i].isAlive()) { -threads[i].interrupt(); -} -} -assertFalse(stillWaiting, "loggerThread didn't finish"); +@BeforeEach +public void startExecutor() { +executor = Executors.newFixedThreadPool(WORKER_COUNT); +} +@AfterEach +public void stopExecutor() throws InterruptedException { +executor.shutdownNow(); +final boolean terminated = executor.awaitTermination(30, TimeUnit.SECONDS); +Assertions.assertTrue(terminated, "couldn't terminate the executor"); } -private static class LoggerThread extends Thread { +@RepeatedTest(100) +public void reconfiguration_should_not_cause_deadlock_for_ongoing_logging() throws Exception { -private final Logger logger = LogManager.getRootLogger(); -private final int index; +// Try to update the config file to ensure that we can indeed update it. +updateConfigFileModTime(); -public LoggerThread(final int i) { -index = i; -} -@Override -public void run() { -int i = 0; +
[logging-log4j2] branch master updated: Reflect recent PR merges to changes.xml.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 0c3b913 Reflect recent PR merges to changes.xml. 0c3b913 is described below commit 0c3b9134b27d6743aada93d7fb82af5afd0f1c86 Author: Volkan Yazıcı AuthorDate: Thu Jul 2 15:15:10 2020 +0200 Reflect recent PR merges to changes.xml. --- src/changes/changes.xml | 6 ++ 1 file changed, 6 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c724b1a..23d7619 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -31,6 +31,12 @@ - "remove" - Removed --> + +JsonLayout KeyValuePair should discard blank JSON keys. + + +Fix exception message in PropertiesConfigurationBuilder#createFilter(). + Reduce Log4j 2 initialization time by deferring loading Plugin classes.
[logging-log4j2] branch master updated (0c3b913 -> 762d163)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 0c3b913 Reflect recent PR merges to changes.xml. add 762d163 LOG4J2-2764 Implement CI pipeline via GitHub Actions. (#379) No new revisions were added by this update. Summary of changes: .../workflows/maven-toolchains.xml | 15 +- .github/workflows/maven.yml| 55 .gitignore | 1 + .mvn/wrapper/maven-wrapper.jar | Bin 49519 -> 50710 bytes .mvn/wrapper/maven-wrapper.properties | 3 +- mvnw | 156 +++-- mvnw.cmd | 54 +-- 7 files changed, 223 insertions(+), 61 deletions(-) copy toolchains-docker.xml => .github/workflows/maven-toolchains.xml (80%) create mode 100644 .github/workflows/maven.yml
[logging-log4j2] branch release-2.x updated: LOG4J2-2749 Jackson version upgrade to fix empty value handling in JsonLayout (#362)
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 583df1a LOG4J2-2749 Jackson version upgrade to fix empty value handling in JsonLayout (#362) 583df1a is described below commit 583df1af9b46ab537cd2a0e657276d814c26618c Author: Oleksii Khomchenko AuthorDate: Tue Jun 30 11:51:39 2020 -0700 LOG4J2-2749 Jackson version upgrade to fix empty value handling in JsonLayout (#362) --- .../apache/logging/log4j/core/layout/JsonLayoutTest.java| 13 + 1 file changed, 13 insertions(+) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java index 561b343..b633f88 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/JsonLayoutTest.java @@ -591,6 +591,19 @@ public class JsonLayoutTest { assertFalse(str.endsWith("\0")); } +@Test // LOG4J2-2749 +public void testEmptyValuesAreIgnored() { +final AbstractJacksonLayout layout = JsonLayout.newBuilder() +.setAdditionalFields(new KeyValuePair[] { +new KeyValuePair("empty", "${ctx:empty:-}") +}) +.setConfiguration(ctx.getConfiguration()) +.build(); + +final String str = layout.toSerializable(LogEventFixtures.createLogEvent()); +assertFalse(str, str.contains("\"empty\"")); +} + private String toPropertySeparator(final boolean compact) { return compact ? ":" : " : "; }
[logging-log4j2] branch master updated: #368 Enable GitHub Dependabot v2.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 26ee69e #368 Enable GitHub Dependabot v2. 26ee69e is described below commit 26ee69e867ef2f592a466b040728e2c262b0e5fc Author: sullis AuthorDate: Tue Jun 30 23:47:32 2020 -0700 #368 Enable GitHub Dependabot v2. https://github.blog/2020-06-01-keep-all-your-packages-up-to-date-with-dependabot/ Dependabot v2 can detect: 1) outdated Maven plugins 2) outdated Java libraries --- .github/dependabot.yml | 24 1 file changed, 24 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000..d0e9890 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,24 @@ +# +# 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. +# +version: 2 +updates: +- package-ecosystem: maven + directory: "/" + schedule: +interval: daily +time: '04:00' + open-pull-requests-limit: 10
[logging-log4j2] branch master updated (26ee69e -> c397c8d)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 26ee69e #368 Enable GitHub Dependabot v2. add 39a17d9 Bump Jackson 2 version to 2.11.1. add c397c8d LOG4J2-2749 #362 Manually copy the JacksonLayout test from release-2.x. No new revisions were added by this update. Summary of changes: .../logging/log4j/jackson/json/layout/JsonLayoutTest.java | 14 ++ pom.xml| 2 +- 2 files changed, 15 insertions(+), 1 deletion(-)
[logging-log4j2] branch master updated: LOG4J2-2344 #359 Fix exception message in PropertiesConfigurationBuilder#createFilter().
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 2a53d68 LOG4J2-2344 #359 Fix exception message in PropertiesConfigurationBuilder#createFilter(). 2a53d68 is described below commit 2a53d6844a78544feb95699ae067ad97b6fd92ef Author: dengliming AuthorDate: Thu Jul 2 15:59:18 2020 +0800 LOG4J2-2344 #359 Fix exception message in PropertiesConfigurationBuilder#createFilter(). --- .../log4j/core/config/properties/PropertiesConfigurationBuilder.java| 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java index 6d52329..41d274f 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java @@ -228,7 +228,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory private FilterComponentBuilder createFilter(final String key, final Properties properties) { final String type = (String) properties.remove(CONFIG_TYPE); if (Strings.isEmpty(type)) { -throw new ConfigurationException("No type attribute provided for Appender " + key); +throw new ConfigurationException("No type attribute provided for Filter " + key); } final String onMatch = (String) properties.remove(AbstractFilterBuilder.ATTR_ON_MATCH); final String onMismatch = (String) properties.remove(AbstractFilterBuilder.ATTR_ON_MISMATCH);
[logging-log4j2] branch master updated: #365 Remove extra curly opening bracket in docs.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new aa16cc4 #365 Remove extra curly opening bracket in docs. aa16cc4 is described below commit aa16cc4da3cabe395eba7269d0b437147bab0c3f Author: Ignas Maslinskas <5737899+ho...@users.noreply.github.com> AuthorDate: Thu Jul 2 11:07:52 2020 +0300 #365 Remove extra curly opening bracket in docs. --- src/site/asciidoc/manual/lookups.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/asciidoc/manual/lookups.adoc b/src/site/asciidoc/manual/lookups.adoc index 06b6c6b..528644e 100644 --- a/src/site/asciidoc/manual/lookups.adoc +++ b/src/site/asciidoc/manual/lookups.adoc @@ -377,7 +377,7 @@ result of a nested lookup. -%d %p %c{1.} [%t] $${lower:{${spring:spring.application.name}} %m%n +%d %p %c{1.} [%t] $${lower:${spring:spring.application.name}} %m%n
[logging-log4j2] branch release-2.x updated: LOG4J2-2344 #359 Fix exception message in PropertiesConfigurationBuilder#createFilter().
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new b70766f LOG4J2-2344 #359 Fix exception message in PropertiesConfigurationBuilder#createFilter(). b70766f is described below commit b70766fc19310a0f1b607c68244286f6b6fc4366 Author: dengliming AuthorDate: Thu Jul 2 15:59:18 2020 +0800 LOG4J2-2344 #359 Fix exception message in PropertiesConfigurationBuilder#createFilter(). --- .../log4j/core/config/properties/PropertiesConfigurationBuilder.java| 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java index f77707e..0a35a1e 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java @@ -228,7 +228,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory private FilterComponentBuilder createFilter(final String key, final Properties properties) { final String type = (String) properties.remove(CONFIG_TYPE); if (Strings.isEmpty(type)) { -throw new ConfigurationException("No type attribute provided for Appender " + key); +throw new ConfigurationException("No type attribute provided for Filter " + key); } final String onMatch = (String) properties.remove(AbstractFilterBuilder.ATTR_ON_MATCH); final String onMismatch = (String) properties.remove(AbstractFilterBuilder.ATTR_ON_MISMATCH);
[logging-log4j2] branch master updated: #335 Add PatternResolver to the manual.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 1c2c57e #335 Add PatternResolver to the manual. 1c2c57e is described below commit 1c2c57e42b3a242b95b355e2b38b732fd167f875 Author: Volkan Yazıcı AuthorDate: Sat Jul 11 20:59:39 2020 +0200 #335 Add PatternResolver to the manual. --- .../json/template/resolver/PatternResolver.java| 17 --- src/site/asciidoc/manual/json-template-layout.adoc | 25 ++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/PatternResolver.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/PatternResolver.java index 727a8e8..d5029e9 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/PatternResolver.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/PatternResolver.java @@ -22,19 +22,26 @@ import org.apache.logging.log4j.layout.json.template.util.JsonWriter; import org.apache.logging.log4j.util.BiConsumer; import org.apache.logging.log4j.util.Strings; +import java.util.Optional; + /** * Resolver delegating to {@link PatternLayout}. * * Configuration * * - * config = pattern - * pattern = "pattern" -> string + * config= pattern , [ stackTraceEnabled ] + * pattern = "pattern" -> string + * stackTraceEnabled = "stackTraceEnabled" -> boolean * * + * The default value of stackTraceEnabled is inherited from the parent + * {@link org.apache.logging.log4j.layout.json.template.JsonTemplateLayout}. + * * Examples * - * Inject string produced by %p %c{1.} [%t] %X{userId} %X %m%ex pattern: + * Resolve the string produced by %p %c{1.} [%t] %X{userId} %X %m%ex + * pattern: * * * { @@ -54,11 +61,15 @@ final class PatternResolver implements EventResolver { if (Strings.isBlank(pattern)) { throw new IllegalArgumentException("blank pattern: " + config); } +final boolean stackTraceEnabled = Optional +.ofNullable(config.getBoolean("stackTraceEnabled")) +.orElse(context.isStackTraceEnabled()); final PatternLayout patternLayout = PatternLayout .newBuilder() .setConfiguration(context.getConfiguration()) .setCharset(context.getCharset()) .setPattern(pattern) +.setAlwaysWriteExceptions(stackTraceEnabled) .build(); this.emitter = (final StringBuilder stringBuilder, final LogEvent logEvent) -> patternLayout.serialize(logEvent, stringBuilder); diff --git a/src/site/asciidoc/manual/json-template-layout.adoc b/src/site/asciidoc/manual/json-template-layout.adoc index dfef200..ff2904d 100644 --- a/src/site/asciidoc/manual/json-template-layout.adoc +++ b/src/site/asciidoc/manual/json-template-layout.adoc @@ -828,6 +828,31 @@ Resolve all NDC values matching with the `pattern` regex: } +| pattern +a| +[source] + +config= pattern , [ stackTraceEnabled ] +pattern = "pattern" -> string +stackTraceEnabled = "stackTraceEnabled" -> boolean + +a| +Resolver delegating to link:layouts.html#PatternLayout[`PatternLayout`]. + +The default value of `stackTraceEnabled` is inherited from the parent +`JsonTemplateLayout`. +| none +a| +Resolve the string produced by `%p %c{1.} [%t] %X{userId} %X %m%ex` pattern: + +[source,json] + +{ + "$resolver": "pattern", + "pattern": "%p %c{1.} [%t] %X{userId} %X %m%ex" +} + + | source a| [source]
[logging-log4j2] branch master updated: #383 Improvements on "extending Log4J" docs. (Jan Materne)
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 09b953c #383 Improvements on "extending Log4J" docs. (Jan Materne) 09b953c is described below commit 09b953c10d446c3050174acec7878347dcf4e441 Author: janmaterne AuthorDate: Sat Jul 11 19:50:54 2020 +0200 #383 Improvements on "extending Log4J" docs. (Jan Materne) --- src/site/asciidoc/manual/extending.adoc | 69 +++-- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/src/site/asciidoc/manual/extending.adoc b/src/site/asciidoc/manual/extending.adoc index 6997928..f8ec37f 100644 --- a/src/site/asciidoc/manual/extending.adoc +++ b/src/site/asciidoc/manual/extending.adoc @@ -26,15 +26,15 @@ supported by the Log4j 2 implementation. The `LoggerContextFactory` binds the Log4j API to its implementation. The Log4j `LogManager` locates a `LoggerContextFactory` by using -java.util.ServiceLoader to locate all instances of +`java.util.ServiceLoader` to locate all instances of `org.apache.logging.log4j.spi.Provider`. Each implementation must -provide a class that extends`org.apache.logging.log4j.spi.Provider` and +provide a class that extends `org.apache.logging.log4j.spi.Provider` and should have a no-arg constructor that delegates to Provider's constructor passing the Priority, the API versions it is compatible with, and the class that implements `org.apache.logging.log4j.spi.LoggerContextFactory`. Log4j will compare -the current API version and if it is compatible the implementation will -be added to the list of providers. The API version in +the current API version and if it is compatible the implementation +will be added to the list of providers. The API version in `org.apache.logging.log4j.LogManager` is only changed when a feature is added to the API that implementations need to be aware of. If more than one valid implementation is located the value for the Priority will be @@ -47,15 +47,15 @@ and bound to the LogManager. In Log4j 2 this is provided by Applications may change the LoggerContextFactory that will be used by 1. Create a binding to the logging implementation. -.. Implement a new `LoggerContextFactory`. -.. Implement a class that extends `org.apache.logging.spi.Provider.` +.. Implement a new link:../log4j-core/apidocs/org/apache/logging/log4j/core/impl/Log4jContextFactory.html[`LoggerContextFactory`]. +.. Implement a class that extends link:../log4j-core/apidocs/org/apache/logging/spi/Provider.html[`org.apache.logging.spi.Provider`] with a no-arg constructor that calls super-class's constructor with the Priority, the API version(s), `LoggerContextFactory` class, and -optionally, a `ThreadContextMap` implementation class. +optionally, a link:../log4j-core/apidocs/org/apache/logging/log4j/spi/ThreadContextMap.html[`ThreadContextMap`] implementation class. .. Create a `META-INF/services/org.apache.logging.spi.Provider` file that contains the name of the class that implements `org.apache.logging.spi.Provider`. -2. Setting the system property log4j2.loggerContextFactory to the name +2. Setting the system property "log4j2.loggerContextFactory" to the name of the `LoggerContextFactory` class to use. 3. Setting the property "log4j2.loggerContextFactory" in a properties file named "log4j2.LogManager.properties" to the name of the @@ -82,7 +82,7 @@ link:../log4j-core/apidocs/org/apache/logging/log4j/core/selector/BasicContextSe common LoggerContext. link:../log4j-core/apidocs/org/apache/logging/log4j/core/selector/ClassLoaderContextSelector.html[`ClassLoaderContextSelector`]:: Associates LoggerContexts with the ClassLoader that created the caller - of the getLogger call. This is the default ContextSelector. + of the getLogger(...) call. This is the default ContextSelector. link:../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html[`JndiContextSelector`]:: Locates the LoggerContext by querying JNDI. link:../log4j-core/apidocs/org/apache/logging/log4j/core/async/AsyncLoggerContextSelector.html[`AsyncLoggerContextSelector`]:: @@ -106,18 +106,16 @@ the name of the class that should be searched first for a configuration. The second method is by defining the `ConfigurationFactory` as a `Plugin`. All the ConfigurationFactories are then processed in order. Each factory -is called on its `getSupportedTypes` method to determine the file +is called on its `getSupportedTypes()` method to determine the file extensions it supports. If a configuration file is located with one of the specified file extensions then control is passed to that -`ConfigurationFactory` to load the configuration and create the -`Configuration` object. +`ConfigurationFactory` to load the configuration and
[logging-log4j2] branch master updated: Update cloud.md: fixes and links
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new a900da1 Update cloud.md: fixes and links a900da1 is described below commit a900da1651b174304bc3aa6a4f7c20ad63533efd Author: janmaterne AuthorDate: Fri Jul 3 14:31:55 2020 +0200 Update cloud.md: fixes and links --- src/site/markdown/manual/cloud.md | 13 +++-- 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/site/markdown/manual/cloud.md b/src/site/markdown/manual/cloud.md index 3eef8f8..e4ad5c1 100644 --- a/src/site/markdown/manual/cloud.md +++ b/src/site/markdown/manual/cloud.md @@ -48,7 +48,8 @@ per logging call vs 1.5 microseconds when writing to the file. 1. When performing audit logging using a framework such as log4j-audit guaranteed delivery of the audit events is required. Many of the options for writing the output, including writing to the standard output stream, do not guarantee delivery. In these cases the event must be delivered to a "forwarder" that acknowledges receipt -only when it has placed the event in durable storage, such as what Apache Flume or Apache Kafka will do. +only when it has placed the event in durable storage, such as what [Apache Flume](https://flume.apache.org/) +or [Apache Kafka](https://kafka.apache.org/) will do. ## Logging Approaches @@ -58,7 +59,7 @@ be used for reporting and alerting. There are many ways to forward and collect e log analysis tools. Note that any approach that bypasses Docker's logging drivers requires Log4j's -[Docker Loookup](lookups.html#DockerLookup) to allow Docker attributes to be injected into the log events. +[Docker Lookup](lookups.html#DockerLookup) to allow Docker attributes to be injected into the log events. ### Logging to the Standard Output Stream @@ -90,9 +91,9 @@ delivered so this method should not be used if a highly available solution is re ### Logging to a File While this is not the recommended 12-Factor approach, it performs very well. However, it requires that the -application declare a volume where the log files will reside and then configure the log forwarder to tail +application declares a volume where the log files will reside and then configures the log forwarder to tail those files. Care must also be taken to automatically manage the disk space used for the logs, which Log4j -can perform via the Delete action on the [RollingFileAppender](appenders.html#RollingFileAppender). +can perform via the "Delete" action on the [RollingFileAppender](appenders.html#RollingFileAppender). ![File](../images/DockerLogFile.png "Logging to a File") @@ -400,7 +401,7 @@ Log4j's Kubernetes support may also be found at [Log4j-Kubernetes](../log4j-kube ## Appender Performance The numbers in the table below represent how much time in seconds was required for the application to -call logger.debug 100,000 times. These numbers only include the time taken to deliver to the specifically +call `logger.debug(...)` 100,000 times. These numbers only include the time taken to deliver to the specifically noted endpoint and many not include the actual time required before they are available for viewing. All measurements were performed on a MacBook Pro with a 2.9GHz Intel Core I9 processor with 6 physical and 12 logical cores, 32GB of 2400 MHz DDR4 RAM, and 1TB of Apple SSD storage. The VM used by Docker was managed @@ -472,4 +473,4 @@ be kept to a minimum since it is much slower than sending buffered events. 1. Logging to files within the container is discouraged. Doing so requires that a volume be declared in the Docker configuration and that the file be tailed by a log forwarder. However, it performs better than logging to the standard output stream. If logging via TCP is not an option and -proper multiline handling is required then consider this option. \ No newline at end of file +proper multiline handling is required then consider this option.
[logging-log4j2] branch master updated: #335 Add nullEventDelimiterEnabled flag.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 7b5aaa8 #335 Add nullEventDelimiterEnabled flag. 7b5aaa8 is described below commit 7b5aaa8434102307df4cb90540703b0deaec393b Author: Volkan Yazıcı AuthorDate: Sat Jul 11 22:38:09 2020 +0200 #335 Add nullEventDelimiterEnabled flag. --- .../layout/json/template/JsonTemplateLayout.java | 23 +++- .../json/template/JsonTemplateLayoutDefaults.java | 9 ++ .../JsonTemplateLayoutNullEventDelimiterTest.java | 127 + .../resources/gcFreeJsonTemplateLayoutLogging.xml | 17 +++ ...nullEventDelimitedJsonTemplateLayoutLogging.xml | 39 +++ .../src/main/config-repo/log4j2.xml| 2 +- src/site/asciidoc/manual/json-template-layout.adoc | 6 + src/site/markdown/manual/cloud.md | 2 +- 8 files changed, 217 insertions(+), 8 deletions(-) diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayout.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayout.java index 7ff3ae9..355816e 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayout.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayout.java @@ -92,7 +92,8 @@ public class JsonTemplateLayout implements StringLayout { private JsonTemplateLayout(final Builder builder) { this.charset = builder.charset; this.contentType = "application/json; charset=" + charset; -this.eventDelimiter = builder.eventDelimiter; +final String eventDelimiterSuffix = builder.isNullEventDelimiterEnabled() ? "\0" : ""; +this.eventDelimiter = builder.eventDelimiter + eventDelimiterSuffix; final Configuration configuration = builder.configuration; final StrSubstitutor substitutor = configuration.getStrSubstitutor(); final JsonWriter jsonWriter = JsonWriter @@ -215,11 +216,7 @@ public class JsonTemplateLayout implements StringLayout { final StringBuilder stringBuilder = jsonWriter.getStringBuilder(); try { eventResolver.resolve(event, jsonWriter); -if (eventDelimiter != null && eventDelimiter.equalsIgnoreCase("null")) { -stringBuilder.append('\0'); -} else { -stringBuilder.append(eventDelimiter); -} +stringBuilder.append(eventDelimiter); return stringBuilder.toString(); } finally { contextRecycler.release(context); @@ -340,6 +337,10 @@ public class JsonTemplateLayout implements StringLayout { private String eventDelimiter = JsonTemplateLayoutDefaults.getEventDelimiter(); @PluginBuilderAttribute +private boolean nullEventDelimiterEnabled = +JsonTemplateLayoutDefaults.isNullEventDelimiterEnabled(); + +@PluginBuilderAttribute private int maxStringLength = JsonTemplateLayoutDefaults.getMaxStringLength(); @PluginBuilderAttribute @@ -447,6 +448,16 @@ public class JsonTemplateLayout implements StringLayout { return this; } +public boolean isNullEventDelimiterEnabled() { +return nullEventDelimiterEnabled; +} + +public Builder setNullEventDelimiterEnabled( +final boolean nullEventDelimiterEnabled) { +this.nullEventDelimiterEnabled = nullEventDelimiterEnabled; +return this; +} + public int getMaxStringLength() { return maxStringLength; } diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayoutDefaults.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayoutDefaults.java index adfe760..7c28b9f 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayoutDefaults.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayoutDefaults.java @@ -79,6 +79,11 @@ public enum JsonTemplateLayoutDefaults {; "log4j.layout.jsonTemplate.eventDelimiter", System.lineSeparator()); +private static final boolean NULL_EVENT_DELIMITER_ENABLED = +PROPERTIES.getBooleanProperty( +"log4j.layout.jsonTemplate.nullEventDelimiterEnabled", +false); + private static final int MAX_STRING_LENGTH = readMaxStringLength(); private static fin
[logging-log4j2] 01/01: LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch LOG4J2-2828 in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 52696e7d6b12a7fa86428b18326a13b685191c06 Author: Volkan Yazıcı AuthorDate: Wed Jun 17 10:25:14 2020 +0200 LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender. --- .../rolling/RollingRandomAccessFileManager.java| 4 ++ .../RollingRandomAccessFileManagerTest.java| 73 -- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java index ad7df84..7f7bf85 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java @@ -22,6 +22,7 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.io.Serializable; import java.nio.ByteBuffer; +import java.nio.file.Paths; import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LoggerContext; @@ -140,6 +141,9 @@ public class RollingRandomAccessFileManager extends RollingFileManager { private void createFileAfterRollover(String fileName) throws IOException { this.randomAccessFile = new RandomAccessFile(fileName, "rw"); +if (isAttributeViewEnabled()) { +defineAttributeView(Paths.get(fileName)); +} if (isAppend()) { randomAccessFile.seek(randomAccessFile.length()); } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java index 8f7f717..c87907a 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java @@ -23,19 +23,25 @@ import static org.apache.logging.log4j.hamcrest.FileMatchers.isEmpty; import static org.apache.logging.log4j.hamcrest.FileMatchers.lastModified; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.RandomAccessFile; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; import java.util.concurrent.locks.LockSupport; +import java.util.zip.Deflater; +import org.apache.logging.log4j.core.config.DefaultConfiguration; import org.apache.logging.log4j.core.util.Closer; +import org.apache.logging.log4j.core.util.FileUtils; import org.apache.logging.log4j.core.util.NullOutputStream; import org.apache.logging.log4j.util.Strings; import org.junit.Test; @@ -198,4 +204,63 @@ public class RollingRandomAccessFileManagerTest { assertThat(file, lastModified(equalTo(manager.getFileTime(; } +@Test +public void testRolloverRetainsFileAttributes() throws Exception { + +// Short-circuit if host doesn't support file attributes. +if (!FileUtils.isFilePosixAttributeViewSupported()) { +return; +} + +// Create the initial file. +final File file = File.createTempFile("log4j2", "test"); +LockSupport.parkNanos(100); // 1 millisec + +// Set the initial file attributes. +final String filePermissionsString = "rwxrwxrwx"; +final Set filePermissions = +PosixFilePermissions.fromString(filePermissionsString); +FileUtils.defineFilePosixAttributeView(file.toPath(), filePermissions, null, null); + +// Create the manager. +final RolloverStrategy rolloverStrategy = DefaultRolloverStrategy +.newBuilder() +.setMax("7") +.setMin("1") +.setFileIndex("max") +.setStopCustomActionsOnError(false) +.setConfig(new DefaultConfiguration()) +.build(); +final RollingRandomAccessFileManager manager = +
[logging-log4j2] branch LOG4J2-2828 created (now 52696e7)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch LOG4J2-2828 in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. at 52696e7 LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender. This branch includes the following new commits: new 52696e7 LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender. The 1 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.
[logging-log4j2] branch LOG4J2-2828 updated (52696e7 -> cbf7acb)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch LOG4J2-2828 in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. discard 52696e7 LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender. new cbf7acb LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender. This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (52696e7) \ N -- N -- N refs/heads/LOG4J2-2828 (cbf7acb) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 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: .../RollingRandomAccessFileManagerTest.java| 31 -- 1 file changed, 17 insertions(+), 14 deletions(-)
[logging-log4j2] 01/01: LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch LOG4J2-2828 in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit cbf7acb2cead757fcabc0a4253f8199f1c2284b1 Author: Volkan Yazıcı AuthorDate: Wed Jun 17 10:25:14 2020 +0200 LOG4J2-2828 Retain file permissions after rollover in RollingRandomAccessFileAppender. --- .../rolling/RollingRandomAccessFileManager.java| 4 + .../RollingRandomAccessFileManagerTest.java| 92 +++--- 2 files changed, 84 insertions(+), 12 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java index ad7df84..7f7bf85 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java @@ -22,6 +22,7 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.io.Serializable; import java.nio.ByteBuffer; +import java.nio.file.Paths; import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LoggerContext; @@ -140,6 +141,9 @@ public class RollingRandomAccessFileManager extends RollingFileManager { private void createFileAfterRollover(String fileName) throws IOException { this.randomAccessFile = new RandomAccessFile(fileName, "rw"); +if (isAttributeViewEnabled()) { +defineAttributeView(Paths.get(fileName)); +} if (isAppend()) { randomAccessFile.seek(randomAccessFile.length()); } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java index 8f7f717..b365322 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java @@ -17,6 +17,26 @@ package org.apache.logging.log4j.core.appender.rolling; +import org.apache.logging.log4j.core.config.DefaultConfiguration; +import org.apache.logging.log4j.core.util.Closer; +import org.apache.logging.log4j.core.util.FileUtils; +import org.apache.logging.log4j.core.util.NullOutputStream; +import org.apache.logging.log4j.util.Strings; +import org.junit.Test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.RandomAccessFile; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; +import java.util.concurrent.locks.LockSupport; + import static org.apache.logging.log4j.hamcrest.FileMatchers.beforeNow; import static org.apache.logging.log4j.hamcrest.FileMatchers.hasLength; import static org.apache.logging.log4j.hamcrest.FileMatchers.isEmpty; @@ -25,21 +45,10 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.RandomAccessFile; -import java.util.concurrent.locks.LockSupport; - -import org.apache.logging.log4j.core.util.Closer; -import org.apache.logging.log4j.core.util.NullOutputStream; -import org.apache.logging.log4j.util.Strings; -import org.junit.Test; - /** * Tests the RollingRandomAccessFileManager class. */ @@ -198,4 +207,63 @@ public class RollingRandomAccessFileManagerTest { assertThat(file, lastModified(equalTo(manager.getFileTime(; } +@Test +public void testRolloverRetainsFileAttributes() throws Exception { + +// Short-circuit if host doesn't support file attributes. +if (!FileUtils.isFilePosixAttributeViewSupported()) { +return; +} + +// Create the initial file. +final File file = File.createTempFile("log4j2", "test"); +LockSupport.parkNanos(100); // 1 millisec + +// Set the initial file attributes. +final String filePermissionsString = "rwxrwxrwx"; +final Set filePermissions = +PosixFilePermissions.fromString(filePermissionsString); +FileUtils.
[logging-log4j2] branch master updated: LOG4J2-2828 Preserve file permissions after rollover in RollingRandomAccessFileAppender. (#364)
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new bdc12dc LOG4J2-2828 Preserve file permissions after rollover in RollingRandomAccessFileAppender. (#364) bdc12dc is described below commit bdc12dcd265ce155591f05ce48e46310a4bf0e66 Author: Volkan Yazıcı AuthorDate: Wed Jun 17 12:40:52 2020 +0200 LOG4J2-2828 Preserve file permissions after rollover in RollingRandomAccessFileAppender. (#364) --- .../rolling/RollingRandomAccessFileManager.java| 4 + .../RollingRandomAccessFileManagerTest.java| 92 +++--- 2 files changed, 84 insertions(+), 12 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java index ad7df84..7f7bf85 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java @@ -22,6 +22,7 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.io.Serializable; import java.nio.ByteBuffer; +import java.nio.file.Paths; import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LoggerContext; @@ -140,6 +141,9 @@ public class RollingRandomAccessFileManager extends RollingFileManager { private void createFileAfterRollover(String fileName) throws IOException { this.randomAccessFile = new RandomAccessFile(fileName, "rw"); +if (isAttributeViewEnabled()) { +defineAttributeView(Paths.get(fileName)); +} if (isAppend()) { randomAccessFile.seek(randomAccessFile.length()); } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java index 8f7f717..b365322 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java @@ -17,6 +17,26 @@ package org.apache.logging.log4j.core.appender.rolling; +import org.apache.logging.log4j.core.config.DefaultConfiguration; +import org.apache.logging.log4j.core.util.Closer; +import org.apache.logging.log4j.core.util.FileUtils; +import org.apache.logging.log4j.core.util.NullOutputStream; +import org.apache.logging.log4j.util.Strings; +import org.junit.Test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.RandomAccessFile; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; +import java.util.concurrent.locks.LockSupport; + import static org.apache.logging.log4j.hamcrest.FileMatchers.beforeNow; import static org.apache.logging.log4j.hamcrest.FileMatchers.hasLength; import static org.apache.logging.log4j.hamcrest.FileMatchers.isEmpty; @@ -25,21 +45,10 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.RandomAccessFile; -import java.util.concurrent.locks.LockSupport; - -import org.apache.logging.log4j.core.util.Closer; -import org.apache.logging.log4j.core.util.NullOutputStream; -import org.apache.logging.log4j.util.Strings; -import org.junit.Test; - /** * Tests the RollingRandomAccessFileManager class. */ @@ -198,4 +207,63 @@ public class RollingRandomAccessFileManagerTest { assertThat(file, lastModified(equalTo(manager.getFileTime(; } +@Test +public void testRolloverRetainsFileAttributes() throws Exception { + +// Short-circuit if host doesn't support file attributes. +if (!FileUtils.isFilePosixAttributeViewSupported()) { +return; +} + +// Create the initial file. +final File file = File.createTempFile("log4j2", "test"); +LockSupport.parkNanos(100); // 1 millisec + +// Set the initial f
[logging-log4j2] branch release-2.x updated: LOG4J2-2828 Preserve file permissions after rollover in RollingRandomAccessFileAppender. (#364)
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 937c877 LOG4J2-2828 Preserve file permissions after rollover in RollingRandomAccessFileAppender. (#364) 937c877 is described below commit 937c8771128300217bc48a2b4368dd101195d0f9 Author: Volkan Yazıcı AuthorDate: Wed Jun 17 12:40:52 2020 +0200 LOG4J2-2828 Preserve file permissions after rollover in RollingRandomAccessFileAppender. (#364) --- .../rolling/RollingRandomAccessFileManager.java| 4 + .../RollingRandomAccessFileManagerTest.java| 92 +++--- 2 files changed, 84 insertions(+), 12 deletions(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java index f5f71d3..b956239 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java @@ -22,6 +22,7 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.io.Serializable; import java.nio.ByteBuffer; +import java.nio.file.Paths; import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LoggerContext; @@ -149,6 +150,9 @@ public class RollingRandomAccessFileManager extends RollingFileManager { private void createFileAfterRollover(final String fileName) throws IOException { this.randomAccessFile = new RandomAccessFile(fileName, "rw"); +if (isAttributeViewEnabled()) { +defineAttributeView(Paths.get(fileName)); +} if (isAppend()) { randomAccessFile.seek(randomAccessFile.length()); } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java index 8fa07b9..e1a1dd3 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java @@ -17,6 +17,26 @@ package org.apache.logging.log4j.core.appender.rolling; +import org.apache.logging.log4j.core.config.DefaultConfiguration; +import org.apache.logging.log4j.core.util.Closer; +import org.apache.logging.log4j.core.util.FileUtils; +import org.apache.logging.log4j.core.util.NullOutputStream; +import org.apache.logging.log4j.util.Strings; +import org.junit.Test; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.RandomAccessFile; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.attribute.PosixFileAttributeView; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Set; +import java.util.concurrent.locks.LockSupport; + import static org.apache.logging.log4j.hamcrest.FileMatchers.beforeNow; import static org.apache.logging.log4j.hamcrest.FileMatchers.hasLength; import static org.apache.logging.log4j.hamcrest.FileMatchers.isEmpty; @@ -25,21 +45,10 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.RandomAccessFile; -import java.util.concurrent.locks.LockSupport; - -import org.apache.logging.log4j.core.util.Closer; -import org.apache.logging.log4j.core.util.NullOutputStream; -import org.apache.logging.log4j.util.Strings; -import org.junit.Test; - /** * Tests the RollingRandomAccessFileManager class. */ @@ -198,4 +207,63 @@ public class RollingRandomAccessFileManagerTest { assertThat(file, lastModified(equalTo(manager.getFileTime(; } +@Test +public void testRolloverRetainsFileAttributes() throws Exception { + +// Short-circuit if host doesn't support file attributes. +if (!FileUtils.isFilePosixAttributeViewSupported()) { +return; +} + +// Create the initial file. +final File file = File.createTempFile("log4j2", "test"); +LockSupport.parkNanos(100); // 1 millisec + +// S
[logging-log4j2] 02/02: #335 Update manual after feedback from Maurice Zeijen.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit e5ab9f8d38968215e78d2eba51f6697746023545 Author: Volkan Yazıcı AuthorDate: Thu Jun 18 16:56:38 2020 +0200 #335 Update manual after feedback from Maurice Zeijen. --- src/site/asciidoc/manual/json-template-layout.adoc | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/site/asciidoc/manual/json-template-layout.adoc b/src/site/asciidoc/manual/json-template-layout.adoc index 1faf985..f3e22db 100644 --- a/src/site/asciidoc/manual/json-template-layout.adoc +++ b/src/site/asciidoc/manual/json-template-layout.adoc @@ -186,7 +186,7 @@ appender.console.json.eventTemplateUri = classpath:LogstashJsonEventLayoutV1.jso property) | eventTemplateAdditionalFields -| KeyValuePair[] +| EventTemplateAdditionalField[] | additional key-value pairs appended to the root of the event template | stackTraceElementTemplate @@ -227,15 +227,18 @@ appender.console.json.eventTemplateUri = classpath:LogstashJsonEventLayoutV1.jso [#additional-event-template-fields] === Additonal event template fields -One can configure additional event template fields via -`eventTemplateAdditionalFields` as follows: +Additional event template field is a convenient short-cut to add custom fields +to a template or override the fields of a template. Following configuration +overrides the `host` field of the `GelfLayout.json` template and adds two new +custom fields: [source,xml] - + - - + + +
[logging-log4j2] 01/02: #335 Update ECS layout compatibility after feedback from Felix Barny.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 5a5f6280b56ed3cd67c9e9ed91be56b0951eaf28 Author: Volkan Yazıcı AuthorDate: Thu Jun 18 16:55:47 2020 +0200 #335 Update ECS layout compatibility after feedback from Felix Barny. --- log4j-layout-json-template/src/main/resources/EcsLayout.json | 4 +--- .../logging/log4j/layout/json/template/EcsLayoutTest.java| 9 - pom.xml | 2 +- src/site/asciidoc/manual/json-template-layout.adoc | 12 +--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/log4j-layout-json-template/src/main/resources/EcsLayout.json b/log4j-layout-json-template/src/main/resources/EcsLayout.json index f5f957b..dee7a84 100644 --- a/log4j-layout-json-template/src/main/resources/EcsLayout.json +++ b/log4j-layout-json-template/src/main/resources/EcsLayout.json @@ -24,9 +24,7 @@ }, "labels": { "$resolver": "mdc", -"flatten": { - "prefix": "labels." -}, +"flatten": true, "stringified": true }, "tags": { diff --git a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/EcsLayoutTest.java b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/EcsLayoutTest.java index 262ddb1..d6cbd30 100644 --- a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/EcsLayoutTest.java +++ b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/EcsLayoutTest.java @@ -4,7 +4,6 @@ import co.elastic.logging.log4j2.EcsLayout; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.DefaultConfiguration; -import org.apache.logging.log4j.core.util.KeyValuePair; import org.apache.logging.log4j.layout.json.template.JsonTemplateLayout.EventTemplateAdditionalField; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -21,6 +20,8 @@ public class EcsLayoutTest { private static final String SERVICE_NAME = "test"; +private static final String EVENT_DATASET = "test.log"; + private static final JsonTemplateLayout JSON_TEMPLATE_LAYOUT = JsonTemplateLayout .newBuilder() .setConfiguration(CONFIGURATION) @@ -35,6 +36,11 @@ public class EcsLayoutTest { .newBuilder() .setKey("service.name") .setValue(SERVICE_NAME) +.build(), +EventTemplateAdditionalField +.newBuilder() +.setKey("event.dataset") +.setValue(EVENT_DATASET) .build() }) .build()) @@ -44,6 +50,7 @@ public class EcsLayoutTest { .newBuilder() .setConfiguration(CONFIGURATION) .setServiceName(SERVICE_NAME) +.setEventDataset(EVENT_DATASET) .build(); @Test diff --git a/pom.xml b/pom.xml index 2c645f4..82ba4c9 100644 --- a/pom.xml +++ b/pom.xml @@ -835,7 +835,7 @@ co.elastic.logging log4j2-ecs-layout -0.1.3 +0.4.0 org.elasticsearch.client diff --git a/src/site/asciidoc/manual/json-template-layout.adoc b/src/site/asciidoc/manual/json-template-layout.adoc index db4bdcd..1faf985 100644 --- a/src/site/asciidoc/manual/json-template-layout.adoc +++ b/src/site/asciidoc/manual/json-template-layout.adoc @@ -270,10 +270,10 @@ prefer one over another is explained below: new instance. This will obviously create a load on the garbage-collector. It is a good choice for applications with low and medium log rate. -* `threadLocal` performs the best, since every instance is stored in TLAB and -accessed without any synchronization cost. Though this might not be a -desirable option for applications running with hundreds of threads or more, -e.g., a web servlet. +* `threadLocal` performs the best, since every instance is stored in +``ThreadLocal``s and accessed without any synchronization cost. Though this +might not be a desirable option for applications running with hundreds of +threads or more, e.g., a web servlet. * `queue` is the best of both worlds. It allows recycling of objects up to a certain number (`capacity`). When this limit is exce
[logging-log4j2] branch master updated (bdc12dc -> e5ab9f8)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from bdc12dc LOG4J2-2828 Preserve file permissions after rollover in RollingRandomAccessFileAppender. (#364) new 5a5f628 #335 Update ECS layout compatibility after feedback from Felix Barny. new e5ab9f8 #335 Update manual after feedback from Maurice Zeijen. The 2 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: .../src/main/resources/EcsLayout.json | 4 +--- .../log4j/layout/json/template/EcsLayoutTest.java | 9 +++- pom.xml| 2 +- src/site/asciidoc/manual/json-template-layout.adoc | 27 +++--- 4 files changed, 24 insertions(+), 18 deletions(-)
[logging-log4j2] 02/03: #335 Fix broken ITs due to recent ECS layout changes.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 631c660d1b55e3f754d747e1baef772d432ca8cf Author: Volkan Yazıcı AuthorDate: Wed Jun 24 08:04:54 2020 +0200 #335 Fix broken ITs due to recent ECS layout changes. --- .../apache/logging/log4j/layout/json/template/EcsLayoutTest.java | 2 +- .../org/apache/logging/log4j/layout/json/template/LogstashIT.java | 8 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/EcsLayoutTest.java b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/EcsLayoutTest.java index d6cbd30..8f5593d 100644 --- a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/EcsLayoutTest.java +++ b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/EcsLayoutTest.java @@ -20,7 +20,7 @@ public class EcsLayoutTest { private static final String SERVICE_NAME = "test"; -private static final String EVENT_DATASET = "test.log"; +private static final String EVENT_DATASET = SERVICE_NAME + ".log"; private static final JsonTemplateLayout JSON_TEMPLATE_LAYOUT = JsonTemplateLayout .newBuilder() diff --git a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/LogstashIT.java b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/LogstashIT.java index 9c30be8..311b0df 100644 --- a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/LogstashIT.java +++ b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/LogstashIT.java @@ -63,6 +63,8 @@ public class LogstashIT { private static final String SERVICE_NAME = "LogstashIT"; +private static final String EVENT_DATASET = SERVICE_NAME + ".log"; + private static final GelfLayout GELF_LAYOUT = GelfLayout .newBuilder() .setConfiguration(CONFIGURATION) @@ -97,6 +99,7 @@ public class LogstashIT { .setConfiguration(CONFIGURATION) .setCharset(CHARSET) .setServiceName(SERVICE_NAME) +.setEventDataset(EVENT_DATASET) .build(); private static final JsonTemplateLayout JSON_TEMPLATE_ECS_LAYOUT = JsonTemplateLayout @@ -114,6 +117,11 @@ public class LogstashIT { .newBuilder() .setKey("service.name") .setValue(SERVICE_NAME) +.build(), +EventTemplateAdditionalField +.newBuilder() +.setKey("event.dataset") +.setValue(EVENT_DATASET) .build() }) .build())
[logging-log4j2] branch master updated (4f841bc -> 18750c1)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from 4f841bc LOG4J2-2877 - Determine the container id to obtain container and image information new c846b21 #335 Add fallbackKey to MessageResolver. new 631c660 #335 Fix broken ITs due to recent ECS layout changes. new 18750c1 #335 Allow non-String values in MapResolver. 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: .../layout/json/template/resolver/MapResolver.java | 32 -- .../json/template/resolver/MessageResolver.java| 116 + .../log4j/layout/json/template/EcsLayoutTest.java | 2 +- .../json/template/JsonTemplateLayoutTest.java | 91 .../log4j/layout/json/template/LogstashIT.java | 8 ++ src/site/asciidoc/manual/json-template-layout.adoc | 32 +- 6 files changed, 222 insertions(+), 59 deletions(-)
[logging-log4j2] 03/03: #335 Allow non-String values in MapResolver.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 18750c1647421a83b6256b5df28447286c772e8b Author: Volkan Yazıcı AuthorDate: Wed Jun 24 08:08:16 2020 +0200 #335 Allow non-String values in MapResolver. --- .../layout/json/template/resolver/MapResolver.java | 32 - .../json/template/JsonTemplateLayoutTest.java | 41 ++ src/site/asciidoc/manual/json-template-layout.adoc | 9 +++-- 3 files changed, 71 insertions(+), 11 deletions(-) diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/MapResolver.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/MapResolver.java index 622d8f3..21d125c 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/MapResolver.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/MapResolver.java @@ -17,9 +17,10 @@ package org.apache.logging.log4j.layout.json.template.resolver; import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.lookup.MapLookup; import org.apache.logging.log4j.layout.json.template.util.JsonWriter; import org.apache.logging.log4j.message.MapMessage; +import org.apache.logging.log4j.message.Message; +import org.apache.logging.log4j.util.IndexedReadOnlyStringMap; /** * {@link MapMessage} field resolver. @@ -27,7 +28,9 @@ import org.apache.logging.log4j.message.MapMessage; * Configuration * * - * config = "key" -> string + * config = key , [ stringified ] + * key = "key" -> string + * stringified = "stringified" -> boolean * * * Examples @@ -43,20 +46,20 @@ import org.apache.logging.log4j.message.MapMessage; */ final class MapResolver implements EventResolver { -private static final MapLookup MAP_LOOKUP = new MapLookup(); - private final String key; +private final boolean stringified; + static String getName() { return "map"; } MapResolver(final TemplateResolverConfig config) { -final String key = config.getString("key"); +this.key = config.getString("key"); +this.stringified = config.getBoolean("stringified", false); if (key == null) { throw new IllegalArgumentException("missing key: " + config); } -this.key = key; } @Override @@ -68,8 +71,21 @@ final class MapResolver implements EventResolver { public void resolve( final LogEvent logEvent, final JsonWriter jsonWriter) { -final String resolvedValue = MAP_LOOKUP.lookup(logEvent, key); -jsonWriter.writeString(resolvedValue); +final Message message = logEvent.getMessage(); +if (!(message instanceof MapMessage)) { +jsonWriter.writeNull(); +} else { +@SuppressWarnings("unchecked") +MapMessage mapMessage = (MapMessage) message; +final IndexedReadOnlyStringMap map = mapMessage.getIndexedReadOnlyStringMap(); +final Object value = map.getValue(key); +if (stringified) { +final String stringifiedValue = String.valueOf(value); +jsonWriter.writeString(stringifiedValue); +} else { +jsonWriter.writeValue(value); +} +} } } diff --git a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayoutTest.java b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayoutTest.java index 4419b58..80cd2b9 100644 --- a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayoutTest.java +++ b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/JsonTemplateLayoutTest.java @@ -322,6 +322,47 @@ public class JsonTemplateLayoutTest { } @Test +public void test_MapMessage_keyed_access() { + +// Create the event template. +final String key = "list"; +final String eventTemplate = writeJson(Map( +"typedValue", Map( +"$resolver", "map", +"key", key), +"stringifiedValue", Map( +"$resolver", "map", +"key", key, +"stringified", true))); + +// Create the layout. +final JsonTemplateLayout layout = JsonTemplateLayout +.newBuilder() +.setConfigu
[logging-log4j2] 01/03: #335 Add fallbackKey to MessageResolver.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit c846b21dcbf9c98d2a96526c3be253a038e3a79e Author: Volkan Yazıcı AuthorDate: Fri Jun 19 10:24:08 2020 +0200 #335 Add fallbackKey to MessageResolver. --- .../json/template/resolver/MessageResolver.java| 116 + .../json/template/JsonTemplateLayoutTest.java | 50 + src/site/asciidoc/manual/json-template-layout.adoc | 23 +++- 3 files changed, 142 insertions(+), 47 deletions(-) diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/MessageResolver.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/MessageResolver.java index 54daefe..53dc7d9 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/MessageResolver.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/MessageResolver.java @@ -18,6 +18,7 @@ package org.apache.logging.log4j.layout.json.template.resolver; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.layout.json.template.util.JsonWriter; +import org.apache.logging.log4j.message.MapMessage; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.MultiformatMessage; import org.apache.logging.log4j.message.ObjectMessage; @@ -30,8 +31,9 @@ import org.apache.logging.log4j.util.StringBuilderFormattable; * Configuration * * - * config = [ stringified ] + * config = [ stringified ] , [ fallbackKey ] * stringified = "stringified" -> boolean + * fallbackKey = "fallbackKey" -> string * * * Examples @@ -54,6 +56,28 @@ import org.apache.logging.log4j.util.StringBuilderFormattable; * "$resolver": "message" * } * + * + * Given the above configuration, a {@link SimpleMessage} will generate a + * "sample log message", whereas a {@link MapMessage} will generate a + * {"action": "login", "sessionId": "87asd97a"}. Certain indexed log + * storage systems (e.g., https://www.elastic.co/elasticsearch/;>Elasticsearch) will not + * allow both values to coexist due to type mismatch: one is a string + * while the other is an object. Here one can use a + * fallbackKey to work around the problem: + * + * + * { + * "$resolver": "message", + * "fallbackKey": "formattedMessage" + * } + * + * + * Using this configuration, a {@link SimpleMessage} will generate a + * {"formattedMessage": "sample log message"} and a {@link MapMessage} + * will generate a {"action": "login", "sessionId": "87asd97a"}. Note + * that both emitted JSONs are of type object and have no + * type-conflicting fields. */ final class MessageResolver implements EventResolver { @@ -72,9 +96,14 @@ final class MessageResolver implements EventResolver { private static EventResolver createInternalResolver( final TemplateResolverConfig config) { final boolean stringified = config.getBoolean("stringified", false); +final String fallbackKey = config.getString("fallbackKey"); +if (stringified && fallbackKey != null) { +throw new IllegalArgumentException( +"fallbackKey is not allowed when stringified is enable: " + config); +} return stringified -? MessageResolver::resolveString -: MessageResolver::resolveObject; +? createStringResolver(fallbackKey) +: createObjectResolver(fallbackKey); } @Override @@ -84,16 +113,27 @@ final class MessageResolver implements EventResolver { internalResolver.resolve(logEvent, jsonWriter); } +private static EventResolver createStringResolver(final String fallbackKey) { +return (final LogEvent logEvent, final JsonWriter jsonWriter) -> +resolveString(fallbackKey, logEvent, jsonWriter); +} + private static void resolveString( +final String fallbackKey, final LogEvent logEvent, final JsonWriter jsonWriter) { final Message message = logEvent.getMessage(); -resolveString(message, jsonWriter); +resolveString(fallbackKey, message, jsonWriter); } private static void resolveString( +final String fallbackKey, final Message message, final JsonWriter jsonWriter) { +if (fallbackKey != null) { +jsonWriter.writeObjectStart(); +jsonWriter.writeObjectKey(fallbackKey); +} if (message instanceo
[logging-log4j2] branch master updated (a529d8d -> 1d47321)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from a529d8d #335 Initial import of JsonTemplateLayout from LogstashLayout. new 0dccbdb #335 Replace inline resolver DSL with JSON structure. new 1d47321 #335 Skip unresolvable entries. The 2 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: .../layout/json/template/JsonTemplateLayout.java | 149 ++- .../json/template/JsonTemplateLayoutDefaults.java |2 +- .../resolver/ContextStackResolverFactory.java | 39 - .../resolver/EndOfBatchResolverFactory.java|4 +- .../template/resolver/EventResolverContext.java| 10 +- .../template/resolver/EventResolverFactories.java |4 +- .../resolver/ExceptionInternalResolverFactory.java | 49 +- .../json/template/resolver/ExceptionResolver.java | 23 +- .../resolver/ExceptionResolverFactory.java | 12 +- .../resolver/ExceptionRootCauseResolver.java | 23 +- .../ExceptionRootCauseResolverFactory.java |6 +- .../json/template/resolver/LevelResolver.java | 85 +- .../template/resolver/LevelResolverFactory.java|6 +- .../json/template/resolver/LoggerResolver.java | 41 +- .../template/resolver/LoggerResolverFactory.java |6 +- .../json/template/resolver/MainMapResolver.java| 49 +- .../template/resolver/MainMapResolverFactory.java |6 +- .../layout/json/template/resolver/MapResolver.java | 41 +- .../json/template/resolver/MapResolverFactory.java |6 +- .../json/template/resolver/MarkerResolver.java | 32 +- .../template/resolver/MarkerResolverFactory.java |6 +- .../json/template/resolver/MessageResolver.java| 62 +- .../template/resolver/MessageResolverFactory.java |6 +- .../json/template/resolver/PatternResolver.java| 30 +- .../template/resolver/PatternResolverFactory.java |6 +- .../json/template/resolver/SourceResolver.java | 41 +- .../template/resolver/SourceResolverFactory.java |6 +- .../resolver/StackTraceElementObjectResolver.java | 36 +- .../StackTraceElementObjectResolverFactory.java|4 +- ...Resolver.java => StackTraceStringResolver.java} |4 +- ...verFactory.java => TemplateResolverConfig.java} | 10 +- .../template/resolver/TemplateResolverFactory.java |2 +- .../json/template/resolver/TemplateResolvers.java | 298 +++--- ...esolver.java => ThreadContextDataResolver.java} | 223 ++-- java => ThreadContextDataResolverFactory.java} | 18 +- ...solver.java => ThreadContextStackResolver.java} | 65 +- ...java => ThreadContextStackResolverFactory.java} | 18 +- .../json/template/resolver/ThreadResolver.java | 34 +- .../template/resolver/ThreadResolverFactory.java |6 +- .../json/template/resolver/TimestampResolver.java | 511 +- .../resolver/TimestampResolverFactory.java |4 +- .../layout/json/template/util/MapAccessor.java | 139 +++ .../src/main/resources/EcsLayout.json | 56 +- .../src/main/resources/GelfLayout.json | 44 +- .../src/main/resources/JsonLayout.json | 95 +- .../main/resources/LogstashJsonEventLayoutV1.json | 65 +- .../main/resources/StackTraceElementLayout.json| 20 +- .../log4j/layout/json/template/EcsLayoutTest.java | 29 +- .../log4j/layout/json/template/GelfLayoutTest.java | 53 +- .../log4j/layout/json/template/JacksonFixture.java |7 - .../log4j/layout/json/template/JsonLayoutTest.java | 57 +- .../json/template/JsonTemplateLayoutTest.java | 1071 +++- .../json/template/LayoutComparisonHelpers.java |6 +- .../log4j/layout/json/template/LogstashIT.java | 24 +- .../src/test/resources/testJsonTemplateLayout.json | 79 +- .../template/JsonTemplateLayoutBenchmarkState.java | 31 +- src/site/asciidoc/manual/json-template-layout.adoc | 917 + src/site/asciidoc/manual/layouts.adoc | 65 +- src/site/markdown/manual/cloud.md | 32 +- 59 files changed, 3217 insertions(+), 1556 deletions(-) delete mode 100644 log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/ContextStackResolverFactory.java rename log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/{StackTraceTextResolver.java => StackTraceStringResolver.java} (93%) copy log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/{TemplateResolverFactory.java => TemplateResolverConfig.java} (79%) rename log4j-layout-json-template/src/main/java/org/apache
[logging-log4j2] 02/02: #335 Skip unresolvable entries.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 1d4732133eae1bb19c55e044fe6274fabf0fcafb Author: Volkan Yazıcı AuthorDate: Sun Jun 7 22:23:45 2020 +0200 #335 Skip unresolvable entries. --- .../json/template/resolver/TemplateResolvers.java | 133 - .../log4j/layout/json/template/JsonLayoutTest.java | 45 ++- .../json/template/JsonTemplateLayoutTest.java | 61 ++ 3 files changed, 170 insertions(+), 69 deletions(-) diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/TemplateResolvers.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/TemplateResolvers.java index ca304b7..8bb11d6 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/TemplateResolvers.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/TemplateResolvers.java @@ -30,21 +30,46 @@ public enum TemplateResolvers {; private static final String RESOLVER_FIELD_NAME = "$resolver"; +private static abstract class UnresolvableTemplateResolver +implements TemplateResolver { + +@Override +public final boolean isResolvable() { +return false; +} + +@Override +public final boolean isResolvable(Object value) { +return false; +} + +} + private static final TemplateResolver EMPTY_ARRAY_RESOLVER = -(final Object ignored, final JsonWriter jsonWriter) -> { -jsonWriter.writeArrayStart(); -jsonWriter.writeArrayEnd(); +new UnresolvableTemplateResolver() { +@Override +public void resolve(final Object value, final JsonWriter jsonWriter) { +jsonWriter.writeArrayStart(); +jsonWriter.writeArrayEnd(); +} }; private static final TemplateResolver EMPTY_OBJECT_RESOLVER = -(final Object ignored, final JsonWriter jsonWriter) -> { -jsonWriter.writeObjectStart(); -jsonWriter.writeObjectEnd(); +new UnresolvableTemplateResolver() { +@Override +public void resolve(final Object value, final JsonWriter jsonWriter) { +jsonWriter.writeObjectStart(); +jsonWriter.writeObjectEnd(); +} }; private static final TemplateResolver NULL_RESOLVER = -(final Object ignored, final JsonWriter jsonWriter) -> +new UnresolvableTemplateResolver() { +@Override +public void resolve(final Object value, final JsonWriter jsonWriter) { jsonWriter.writeNull(); +} +}; public static > TemplateResolver ofTemplate( final C context, @@ -236,36 +261,80 @@ public enum TemplateResolvers {; }) .collect(Collectors.toList()); -// Create a parent resolver collecting each object field resolver execution. -return (value, jsonWriter) -> { -final StringBuilder jsonWriterStringBuilder = jsonWriter.getStringBuilder(); -jsonWriter.writeObjectStart(); -for (int resolvedFieldCount = 0, fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) { -final TemplateResolver fieldResolver = fieldResolvers.get(fieldIndex); -final boolean resolvable = fieldResolver.isResolvable(value); -if (!resolvable) { -continue; +return new TemplateResolver() { + +/** + * The parent resolver checking if each child is resolvable. + * + * This is an optimization to skip the rendering of a parent if all + * its children are not resolvable. + */ +@Override +public boolean isResolvable() { +for (int fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) { +final TemplateResolver fieldResolver = fieldResolvers.get(fieldIndex); +final boolean resolvable = fieldResolver.isResolvable(); +if (resolvable) { +return true; +} +} +return false; +} + +/** + * The parent resolver checking if each child is resolvable given + * the passed {@code value}. + * + * This is an optimization to skip the rendering of a parent if all + * its children are not resolvable given the passed {@code value}. +
[logging-log4j2] branch master updated: #335 Remove redundant resolvability check.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new f781fc5 #335 Remove redundant resolvability check. f781fc5 is described below commit f781fc5a6e0e050da923f3c458218e2eb368c615 Author: Volkan Yazıcı AuthorDate: Thu Jun 11 10:12:43 2020 +0200 #335 Remove redundant resolvability check. --- .../json/template/resolver/TemplateResolvers.java | 17 +++-- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/TemplateResolvers.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/TemplateResolvers.java index 8bb11d6..a4b1165 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/TemplateResolvers.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/TemplateResolvers.java @@ -263,22 +263,11 @@ public enum TemplateResolvers {; return new TemplateResolver() { -/** - * The parent resolver checking if each child is resolvable. - * - * This is an optimization to skip the rendering of a parent if all - * its children are not resolvable. - */ @Override public boolean isResolvable() { -for (int fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++) { -final TemplateResolver fieldResolver = fieldResolvers.get(fieldIndex); -final boolean resolvable = fieldResolver.isResolvable(); -if (resolvable) { -return true; -} -} -return false; +// We have already excluded unresolvable ones while collecting +// the resolvers. Hence it is safe to return true here. +return true; } /**
[logging-log4j2] branch master updated: #335 Fix adoc typo.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 512bb4d #335 Fix adoc typo. 512bb4d is described below commit 512bb4d9b33489c38be1cf76559f8f607a1aea43 Author: Volkan Yazıcı AuthorDate: Fri Jun 12 09:40:24 2020 +0200 #335 Fix adoc typo. --- src/site/asciidoc/manual/json-template-layout.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/asciidoc/manual/json-template-layout.adoc b/src/site/asciidoc/manual/json-template-layout.adoc index d541dc2..d49d8fe 100644 --- a/src/site/asciidoc/manual/json-template-layout.adoc +++ b/src/site/asciidoc/manual/json-template-layout.adoc @@ -737,7 +737,7 @@ stringified = "stringified" -> boolean a| `logEvent.getMessage()` | For simple string messages, the resolution is performed without allocations. - For `ObjectMessage`s and `MultiformatMessage`s, it depends. + For ``ObjectMessage``s and ``MultiformatMessage``s, it depends. a| Resolve the message into a string:
[logging-log4j2] branch master updated: #335 Cosmetic changes.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 8591745 #335 Cosmetic changes. 8591745 is described below commit 85917452039fdeba668522c5663a54d09e058e60 Author: Volkan Yazıcı AuthorDate: Fri Jun 12 11:46:27 2020 +0200 #335 Cosmetic changes. --- .../log4j/layout/json/template/resolver/ThreadContextDataResolver.java | 1 - src/site/asciidoc/manual/json-template-layout.adoc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/ThreadContextDataResolver.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/ThreadContextDataResolver.java index a2671fb..66efe17 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/ThreadContextDataResolver.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/resolver/ThreadContextDataResolver.java @@ -169,7 +169,6 @@ final class ThreadContextDataResolver implements EventResolver { final ReadOnlyStringMap contextData = logEvent.getContextData(); final Object value = contextData == null ? null : contextData.getValue(key); if (stringified) { -// TODO Write the value as string without extra allocations. final String valueString = String.valueOf(value); jsonWriter.writeString(valueString); } else { diff --git a/src/site/asciidoc/manual/json-template-layout.adoc b/src/site/asciidoc/manual/json-template-layout.adoc index d49d8fe..db4bdcd 100644 --- a/src/site/asciidoc/manual/json-template-layout.adoc +++ b/src/site/asciidoc/manual/json-template-layout.adoc @@ -656,7 +656,7 @@ a| `log4j2.garbagefreeThreadContextMap` flag needs to be turned on to iterate the map without allocations. -`stringify` allocates a new `String` for values that are not of type `String`. +`stringified` allocates a new `String` for values that are not of type `String`. Writing certain non-primitive values (e.g., `BigDecimal`, `Set`, etc.) to JSON generates garbage, though most (e.g., `int`, `long`, `String`, `List`,
[logging-log4j2] branch master updated: #335 Fix reading of Windows paths in Uris.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 6debe00 #335 Fix reading of Windows paths in Uris. 6debe00 is described below commit 6debe0038255db12c5438cea54075c845b7d5ae1 Author: Volkan Yazıcı AuthorDate: Tue Jun 9 11:30:11 2020 +0200 #335 Fix reading of Windows paths in Uris. --- .../log4j/layout/json/template/util/Uris.java | 34 +++--- .../log4j/layout/json/template/util/UrisTest.java | 3 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/util/Uris.java b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/util/Uris.java index 4c03843..65cd863 100644 --- a/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/util/Uris.java +++ b/log4j-layout-json-template/src/main/java/org/apache/logging/log4j/layout/json/template/util/Uris.java @@ -39,7 +39,7 @@ public enum Uris {; private static final Logger LOGGER = StatusLogger.getLogger(); /** - * Reads {@link URI}s of scheme classpath and file. + * Reads {@link URI} specs of scheme classpath and file. * * @param spec the {@link URI} spec, e.g., file:/holy/cow.txt or * classpath:/holy/cat.txt @@ -49,20 +49,34 @@ public enum Uris {; Objects.requireNonNull(spec, "spec"); Objects.requireNonNull(charset, "charset"); try { -return unsafeReadUri(spec, charset); +final URI uri = new URI(spec); +return unsafeReadUri(uri, charset); } catch (final Exception error) { -final String message = String.format( -"failed reading URI (spec=%s, charset=%s)", -spec, charset); -throw new RuntimeException(message, error); +throw new RuntimeException("failed reading URI: " + spec, error); +} +} + +/** + * Reads {@link URI}s of scheme classpath and file. + * + * @param uri the {@link URI}, e.g., file:/holy/cow.txt or + * classpath:/holy/cat.txt + * @param charset used {@link Charset} for decoding the file + */ +public static String readUri(final URI uri, final Charset charset) { +Objects.requireNonNull(uri, "uri"); +Objects.requireNonNull(charset, "charset"); +try { +return unsafeReadUri(uri, charset); +} catch (final Exception error) { +throw new RuntimeException("failed reading URI: " + uri, error); } } private static String unsafeReadUri( -final String spec, +final URI uri, final Charset charset) throws Exception { -final URI uri = new URI(spec); final String uriScheme = uri.getScheme().toLowerCase(); switch (uriScheme) { case "classpath": @@ -70,11 +84,9 @@ public enum Uris {; case "file": return readFileUri(uri, charset); default: { -final String message = String.format("unknown URI scheme (spec=%s)", spec); -throw new IllegalArgumentException(message); +throw new IllegalArgumentException("unknown scheme in URI: " + uri); } } - } private static String readFileUri( diff --git a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/util/UrisTest.java b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/util/UrisTest.java index a70bbeb..05e679b 100644 --- a/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/util/UrisTest.java +++ b/log4j-layout-json-template/src/test/java/org/apache/logging/log4j/layout/json/template/util/UrisTest.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -50,7 +51,7 @@ public class UrisTest { try (final OutputStream outputStream = new FileOutputStream(file)) { outputStream.write(nonAsciiUtfText.getBytes(StandardCharsets.UTF_8)); } -final String uri = String.format("file:%s", file.getAbsoluteFile()); +final URI uri = file.toURI(); final String content = Uris.readUri(uri, StandardCharsets.UTF_8); Assert.assertEquals(nonAsciiUtfText, content); } finally {
[logging-log4j2] branch master updated (f6578ea -> ff76b82)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from f6578ea LOG4J2-2908 - Move Spring Lookup and Spring properties to a new Spring Boot module add ff76b82 Add MacOS to GitHub Actions. No new revisions were added by this update. Summary of changes: .github/workflows/maven.yml | 22 +++--- 1 file changed, 19 insertions(+), 3 deletions(-)
[logging-log4j2] branch master updated (ff76b82 -> d0fe63a)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. omit ff76b82 Add MacOS to GitHub Actions. new d0fe63a Add MacOS to GitHub Actions. This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (ff76b82) \ N -- N -- N refs/heads/master (d0fe63a) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 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: .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[logging-log4j2] 01/01: Add MacOS to GitHub Actions.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit d0fe63a069fbb4918a7baf683171d1588f49bd37 Author: Volkan Yazıcı AuthorDate: Fri Aug 14 11:26:00 2020 +0200 Add MacOS to GitHub Actions. --- .github/workflows/maven.yml | 22 +++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 47c8f07..b99a32e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: -os: [ubuntu-latest, windows-latest] +os: [ubuntu-latest, windows-latest, macos-latest] steps: @@ -51,7 +51,7 @@ jobs: uses: scacap/action-surefire-report@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} - check_name: 'Linux Test Report' + check_name: 'Test Report (Linux)' report_paths: '**/*-reports/TEST-*.xml' - name: Inspect environment (Windows) @@ -67,5 +67,21 @@ jobs: uses: scacap/action-surefire-report@v1 with: github_token: ${{ secrets.GITHUB_TOKEN }} - check_name: 'Windows Test Report' + check_name: 'Test Report (Windows)' + report_paths: '**/*-reports/TEST-*.xml' + + - name: Inspect environment (MacOS) +if: runner.os == 'macOS' +run: env | grep '^JAVA' + + - name: Build with Maven (MacOS) +if: runner.os == 'macOS' +run: ./mvnw -V -B -e -DtrimStackTrace=false -Dmaven.test.failure.ignore=true -Dsurefire.rerunFailingTestsCount=1 --global-toolchains .github/workflows/maven-toolchains.xml verify + + - name: Publish Test Results (MacOS) +if: runner.os == 'macOS' +uses: scacap/action-surefire-report@v1 +with: + github_token: ${{ secrets.GITHUB_TOKEN }} + check_name: 'Test Report (MacOS)' report_paths: '**/*-reports/TEST-*.xml'
[logging-log4j2] branch release-2.x updated: Migrate JTL tests to JUnit 5.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 979aa6e Migrate JTL tests to JUnit 5. 979aa6e is described below commit 979aa6e1cabc291e78b6603ac863bdcab25bc6c0 Author: Volkan Yazıcı AuthorDate: Fri Nov 27 11:13:27 2020 +0100 Migrate JTL tests to JUnit 5. --- log4j-layout-template-json/pom.xml | 29 +- .../log4j/layout/template/json/EcsLayoutTest.java | 8 +- .../log4j/layout/template/json/GelfLayoutTest.java | 8 +- .../log4j/layout/template/json/JsonLayoutTest.java | 8 +- .../JsonTemplateLayoutConcurrentEncodeTest.java| 6 +- .../json/JsonTemplateLayoutGcFreeTest.java | 4 +- .../JsonTemplateLayoutNullEventDelimiterTest.java | 4 +- .../template/json/JsonTemplateLayoutTest.java | 74 ++-- .../log4j/layout/template/json/LogstashIT.java | 17 +- .../layout/template/json/util/JsonReaderTest.java | 62 +-- .../layout/template/json/util/JsonWriterTest.java | 485 - .../template/json/util/RecyclerFactoriesTest.java | 6 +- .../json/util/StringParameterParserTest.java | 85 ++-- .../json/util/TruncatingBufferedWriterTest.java| 34 +- .../log4j/layout/template/json/util/UrisTest.java | 16 +- 15 files changed, 463 insertions(+), 383 deletions(-) diff --git a/log4j-layout-template-json/pom.xml b/log4j-layout-template-json/pom.xml index a2fce5f..2a435e3 100644 --- a/log4j-layout-template-json/pom.xml +++ b/log4j-layout-template-json/pom.xml @@ -177,17 +177,33 @@ org.apache.maven.plugins maven-surefire-plugin - ${maven.test.skip} - -**/JsonTemplateLayoutConcurrentEncodeTest.java -**/JsonTemplateLayoutTest.java - + + true -Dfile.encoding=US-ASCII + + + true + concurrent + + +default + + test + + + ${skipTests} + + **/JsonTemplateLayoutConcurrentEncodeTest.java +**/JsonTemplateLayoutTest.java + + + recycler-dummy @@ -197,7 +213,7 @@ ${skipTests} - threadLocal + dummy **/JsonTemplateLayoutConcurrentEncodeTest.java @@ -300,7 +316,6 @@ - ${skipTests} **/*IT.java diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java index 4be0c7f..9f806f5 100644 --- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java +++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java @@ -22,7 +22,7 @@ import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.DefaultConfiguration; import org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.EventTemplateAdditionalField; import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.List; @@ -30,7 +30,7 @@ import java.util.Map; import static org.apache.logging.log4j.layout.template.json.LayoutComparisonHelpers.renderUsing; -public class EcsLayoutTest { +class EcsLayoutTest { private static final Configuration CONFIGURATION = new DefaultConfiguration(); @@ -65,13 +65,13 @@ public class EcsLayoutTest { .build(); @Test -public void test_lite_log_events() { +void test_lite_log_events() { final List logEvents = LogEventFixture.createLiteLogEvents(1_000); test(logEvents); } @Test -public void test_full_log_events() { +void test_full_log_events() { final List logEvents = LogEventFixture.createFullLogEvents(1_000); test(logEvents); } diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/GelfLayoutTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/GelfLayoutTest.java index 9d32cf3..7601d44 100644 --- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/GelfLayoutTest.java +++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/GelfLayoutTest.java @@ -23,7 +23,7
[logging-log4j2] branch master updated (ee1328a -> adf3758)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from ee1328a LOG4J2-2962 Enrich "map" resolver by unifying its backend with "mdc" resolver. add adf3758 Migrate JTL tests to JUnit 5. No new revisions were added by this update. Summary of changes: log4j-layout-template-json/pom.xml | 29 +- .../log4j/layout/template/json/EcsLayoutTest.java | 8 +- .../log4j/layout/template/json/GelfLayoutTest.java | 8 +- .../log4j/layout/template/json/JsonLayoutTest.java | 8 +- .../JsonTemplateLayoutConcurrentEncodeTest.java| 6 +- .../json/JsonTemplateLayoutGcFreeTest.java | 4 +- .../JsonTemplateLayoutNullEventDelimiterTest.java | 4 +- .../template/json/JsonTemplateLayoutTest.java | 74 ++-- .../log4j/layout/template/json/LogstashIT.java | 17 +- .../layout/template/json/util/JsonReaderTest.java | 62 +-- .../layout/template/json/util/JsonWriterTest.java | 485 - .../template/json/util/RecyclerFactoriesTest.java | 6 +- .../json/util/StringParameterParserTest.java | 85 ++-- .../json/util/TruncatingBufferedWriterTest.java| 34 +- .../log4j/layout/template/json/util/UrisTest.java | 16 +- 15 files changed, 463 insertions(+), 383 deletions(-)
[logging-log4j2] branch master updated: LOG4J2-2967 Fix JTL parameter resolution for messages with too few parameters. (#443)
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new d728835 LOG4J2-2967 Fix JTL parameter resolution for messages with too few parameters. (#443) d728835 is described below commit d7288357f89e01d6d4877ba202e4153dcc31d723 Author: Carter Kozak AuthorDate: Mon Nov 30 03:55:51 2020 -0500 LOG4J2-2967 Fix JTL parameter resolution for messages with too few parameters. (#443) --- .../json/resolver/MessageParameterResolver.java| 14 +- .../template/json/JsonTemplateLayoutTest.java | 282 - src/changes/changes.xml| 3 + 3 files changed, 181 insertions(+), 118 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java index 059e5b1..866b3d1 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java @@ -111,8 +111,13 @@ final class MessageParameterResolver implements EventResolver { // Short-circuit if there are no parameters. final Object[] parameters = message.getParameters(); -if (parameters == null || parameters.length == 0) { -jsonWriter.writeNull(); +if (parameters == null || parameters.length == 0 || index >= parameters.length) { +if (index < 0) { +jsonWriter.writeArrayStart(); +jsonWriter.writeArrayEnd(); +} else { +jsonWriter.writeNull(); +} return; } @@ -162,12 +167,17 @@ final class MessageParameterResolver implements EventResolver { if (arrayNeeded) { jsonWriter.writeArrayStart(); } +final StringBuilder buf = jsonWriter.getStringBuilder(); +final int startIndex = buf.length(); parameterConsumerState.resolver = this; parameterConsumerState.jsonWriter = jsonWriter; parameterVisitable.forEachParameter( PARAMETER_CONSUMER, parameterConsumerState); if (arrayNeeded) { jsonWriter.writeArrayEnd(); +} else if (startIndex == buf.length()) { +// Handle the case in which index was not present in the event. +jsonWriter.writeNull(); } } finally { parameterConsumerStateRecycler.release(parameterConsumerState); diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutTest.java index a7503fc..f8d4990 100644 --- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutTest.java +++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutTest.java @@ -225,10 +225,10 @@ class JsonTemplateLayoutTest { final String timestampFieldName = "@timestamp"; final String staticFieldName = "staticFieldName"; final String staticFieldValue = "staticFieldValue"; -final String eventTemplate = writeJson(Map( -timestampFieldName, Map( +final String eventTemplate = writeJson(asMap( +timestampFieldName, asMap( "$resolver", "timestamp", -"pattern", Map("timeZone", "Europe/Amsterdam")), +"pattern", asMap("timeZone", "Europe/Amsterdam")), staticFieldName, staticFieldValue)); // Create the layout. @@ -250,8 +250,8 @@ class JsonTemplateLayoutTest { void test_log4j_deferred_runtime_resolver_for_MapMessage() { // Create the event template. -final String eventTemplate = writeJson(Map( -"mapValue3", Map("$resolver", "message"), +final String eventTemplate = writeJson(asMap( +"mapValue3", asMap("$resolver", "message"), "mapValue1", "${map:key1}", "mapValue2", "${map:key2}", "nestedLookupEmptyValue", "${map:noExist:-${map:noExist2:-${map:noExist3:-}}}", @@ -29
[logging-log4j2] branch release-2.x updated: LOG4J2-2967 Fix JTL parameter resolution for messages with too few parameters. (#443)
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 1a3070d LOG4J2-2967 Fix JTL parameter resolution for messages with too few parameters. (#443) 1a3070d is described below commit 1a3070d95af5bb11af835fd145dca9233aa9ee37 Author: Carter Kozak AuthorDate: Mon Nov 30 03:55:51 2020 -0500 LOG4J2-2967 Fix JTL parameter resolution for messages with too few parameters. (#443) When messages don't contain enough parameters, index-based lookups result in a JSON null token rather than failing to produce a log event. This change also modifies behavior of non-index-based resolution when messages have no parameters. Previously the value would be null, now we produce an empty list. Note that this is a change for only ParameterizedMessage, not for messages which implement ParameterVisitable. --- .../json/resolver/MessageParameterResolver.java| 14 +- .../template/json/JsonTemplateLayoutTest.java | 282 - src/changes/changes.xml| 3 + 3 files changed, 181 insertions(+), 118 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java index 059e5b1..866b3d1 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java @@ -111,8 +111,13 @@ final class MessageParameterResolver implements EventResolver { // Short-circuit if there are no parameters. final Object[] parameters = message.getParameters(); -if (parameters == null || parameters.length == 0) { -jsonWriter.writeNull(); +if (parameters == null || parameters.length == 0 || index >= parameters.length) { +if (index < 0) { +jsonWriter.writeArrayStart(); +jsonWriter.writeArrayEnd(); +} else { +jsonWriter.writeNull(); +} return; } @@ -162,12 +167,17 @@ final class MessageParameterResolver implements EventResolver { if (arrayNeeded) { jsonWriter.writeArrayStart(); } +final StringBuilder buf = jsonWriter.getStringBuilder(); +final int startIndex = buf.length(); parameterConsumerState.resolver = this; parameterConsumerState.jsonWriter = jsonWriter; parameterVisitable.forEachParameter( PARAMETER_CONSUMER, parameterConsumerState); if (arrayNeeded) { jsonWriter.writeArrayEnd(); +} else if (startIndex == buf.length()) { +// Handle the case in which index was not present in the event. +jsonWriter.writeNull(); } } finally { parameterConsumerStateRecycler.release(parameterConsumerState); diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutTest.java index 4198861..3d482fe 100644 --- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutTest.java +++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutTest.java @@ -225,10 +225,10 @@ class JsonTemplateLayoutTest { final String timestampFieldName = "@timestamp"; final String staticFieldName = "staticFieldName"; final String staticFieldValue = "staticFieldValue"; -final String eventTemplate = writeJson(Map( -timestampFieldName, Map( +final String eventTemplate = writeJson(asMap( +timestampFieldName, asMap( "$resolver", "timestamp", -"pattern", Map("timeZone", "Europe/Amsterdam")), +"pattern", asMap("timeZone", "Europe/Amsterdam")), staticFieldName, staticFieldValue)); // Create the layout. @@ -250,8 +250,8 @@ class JsonTemplateLayoutTest { void test_log4j_deferred_runtime_resolver_for_MapMessage() { // Create the event template. -final String eventTemplate = writeJson(Map( -"mapValue3&
[logging-log4j2] branch master updated: LOG4J2-2966 Replace String.valueOf() usages with ParameterizedMessage.deepToString().
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 6db78fb LOG4J2-2966 Replace String.valueOf() usages with ParameterizedMessage.deepToString(). 6db78fb is described below commit 6db78fbd0ab11644cad551c7a554787f8d88f98b Author: Volkan Yazıcı AuthorDate: Fri Nov 27 17:04:41 2020 +0100 LOG4J2-2966 Replace String.valueOf() usages with ParameterizedMessage.deepToString(). --- .../template/json/resolver/MessageParameterResolver.java | 10 +++--- .../template/json/resolver/ReadOnlyStringMapResolver.java | 6 -- .../log4j/layout/template/json/resolver/TemplateResolvers.java | 3 ++- .../log4j/layout/template/json/resolver/TimestampResolver.java | 7 +-- .../logging/log4j/layout/template/json/util/JsonWriter.java| 3 ++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java index b4d39f3..059e5b1 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java @@ -22,6 +22,7 @@ import org.apache.logging.log4j.layout.template.json.util.Recycler; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.ParameterConsumer; import org.apache.logging.log4j.message.ParameterVisitable; +import org.apache.logging.log4j.message.ParameterizedMessage; /** * {@link Message} parameter (i.e., {@link Message#getParameters()}) resolver. @@ -124,7 +125,8 @@ final class MessageParameterResolver implements EventResolver { } final Object parameter = parameters[i]; if (stringified) { -final String stringifiedParameter = String.valueOf(parameter); +final String stringifiedParameter = +ParameterizedMessage.deepToString(parameter); jsonWriter.writeString(stringifiedParameter); } else { jsonWriter.writeValue(parameter); @@ -137,7 +139,8 @@ final class MessageParameterResolver implements EventResolver { else { final Object parameter = parameters[index]; if (stringified) { -final String stringifiedParameter = String.valueOf(parameter); +final String stringifiedParameter = +ParameterizedMessage.deepToString(parameter); jsonWriter.writeString(stringifiedParameter); } else { jsonWriter.writeValue(parameter); @@ -193,7 +196,8 @@ final class MessageParameterResolver implements EventResolver { // Write the value. if (arrayNeeded || state.resolver.index == index) { if (state.resolver.stringified) { -final String stringifiedParameter = String.valueOf(parameter); +final String stringifiedParameter = +ParameterizedMessage.deepToString(parameter); state.jsonWriter.writeString(stringifiedParameter); } else { state.jsonWriter.writeValue(parameter); diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java index 3735017..05164c9 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java @@ -20,6 +20,7 @@ import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.layout.template.json.util.JsonWriter; import org.apache.logging.log4j.layout.template.json.util.Recycler; import org.apache.logging.log4j.layout.template.json.util.RecyclerFactory; +import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.util.TriConsumer; @@ -201,7 +202,8 @@ class ReadOnlyStringMapResolver implements EventResolver { final ReadOnlyStringMap map = mapAccessor.apply(logEvent); final Object value = map == null ? null : map.getValue(key
[logging-log4j2] branch release-2.x updated: LOG4J2-2966 Replace String.valueOf() usages with ParameterizedMessage.deepToString().
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new f8a9a5a LOG4J2-2966 Replace String.valueOf() usages with ParameterizedMessage.deepToString(). f8a9a5a is described below commit f8a9a5a146dfd7aa0cadd09e51b4e9237470ab5b Author: Volkan Yazıcı AuthorDate: Fri Nov 27 17:04:41 2020 +0100 LOG4J2-2966 Replace String.valueOf() usages with ParameterizedMessage.deepToString(). --- .../template/json/resolver/MessageParameterResolver.java | 10 +++--- .../template/json/resolver/ReadOnlyStringMapResolver.java | 6 -- .../log4j/layout/template/json/resolver/TemplateResolvers.java | 3 ++- .../log4j/layout/template/json/resolver/TimestampResolver.java | 5 - .../logging/log4j/layout/template/json/util/JsonWriter.java| 3 ++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java index b4d39f3..059e5b1 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java @@ -22,6 +22,7 @@ import org.apache.logging.log4j.layout.template.json.util.Recycler; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.ParameterConsumer; import org.apache.logging.log4j.message.ParameterVisitable; +import org.apache.logging.log4j.message.ParameterizedMessage; /** * {@link Message} parameter (i.e., {@link Message#getParameters()}) resolver. @@ -124,7 +125,8 @@ final class MessageParameterResolver implements EventResolver { } final Object parameter = parameters[i]; if (stringified) { -final String stringifiedParameter = String.valueOf(parameter); +final String stringifiedParameter = +ParameterizedMessage.deepToString(parameter); jsonWriter.writeString(stringifiedParameter); } else { jsonWriter.writeValue(parameter); @@ -137,7 +139,8 @@ final class MessageParameterResolver implements EventResolver { else { final Object parameter = parameters[index]; if (stringified) { -final String stringifiedParameter = String.valueOf(parameter); +final String stringifiedParameter = +ParameterizedMessage.deepToString(parameter); jsonWriter.writeString(stringifiedParameter); } else { jsonWriter.writeValue(parameter); @@ -193,7 +196,8 @@ final class MessageParameterResolver implements EventResolver { // Write the value. if (arrayNeeded || state.resolver.index == index) { if (state.resolver.stringified) { -final String stringifiedParameter = String.valueOf(parameter); +final String stringifiedParameter = +ParameterizedMessage.deepToString(parameter); state.jsonWriter.writeString(stringifiedParameter); } else { state.jsonWriter.writeValue(parameter); diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java index 3735017..05164c9 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java @@ -20,6 +20,7 @@ import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.layout.template.json.util.JsonWriter; import org.apache.logging.log4j.layout.template.json.util.Recycler; import org.apache.logging.log4j.layout.template.json.util.RecyclerFactory; +import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.ReadOnlyStringMap; import org.apache.logging.log4j.util.TriConsumer; @@ -201,7 +202,8 @@ class ReadOnlyStringMapResolver implements EventResolver { final ReadOnlyStringMap map = mapAccessor.apply(logEvent); final Object value = map == null ? null : map.getValue(key
[logging-log4j2] branch release-2.x updated (2aa2be7 -> a62902d)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. discard 2aa2be7 Migrate JTL tests to JUnit 5. This update removed existing revisions from the reference, leaving the reference pointing at a previous point in the repository history. * -- * -- N refs/heads/release-2.x (a62902d) \ O -- O -- O (2aa2be7) Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. No new revisions were added by this update. Summary of changes: log4j-layout-template-json/pom.xml | 20 +-- .../log4j/layout/template/json/EcsLayoutTest.java | 8 +- .../log4j/layout/template/json/GelfLayoutTest.java | 8 +- .../log4j/layout/template/json/JsonLayoutTest.java | 8 +- .../JsonTemplateLayoutConcurrentEncodeTest.java| 6 +- .../json/JsonTemplateLayoutGcFreeTest.java | 4 +- .../JsonTemplateLayoutNullEventDelimiterTest.java | 4 +- .../template/json/JsonTemplateLayoutTest.java | 74 +-- .../log4j/layout/template/json/LogstashIT.java | 17 +-- .../layout/template/json/util/JsonReaderTest.java | 62 - .../layout/template/json/util/JsonWriterTest.java | 146 ++--- .../template/json/util/RecyclerFactoriesTest.java | 6 +- .../json/util/StringParameterParserTest.java | 84 ++-- .../json/util/TruncatingBufferedWriterTest.java| 34 ++--- .../log4j/layout/template/json/util/UrisTest.java | 16 ++- 15 files changed, 248 insertions(+), 249 deletions(-)
[logging-log4j2] branch master updated (2a90efd -> ee1328a)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. discard 2a90efd Migrate JTL tests to JUnit 5. This update removed existing revisions from the reference, leaving the reference pointing at a previous point in the repository history. * -- * -- N refs/heads/master (ee1328a) \ O -- O -- O (2a90efd) Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. No new revisions were added by this update. Summary of changes: log4j-layout-template-json/pom.xml | 20 +-- .../log4j/layout/template/json/EcsLayoutTest.java | 8 +- .../log4j/layout/template/json/GelfLayoutTest.java | 8 +- .../log4j/layout/template/json/JsonLayoutTest.java | 8 +- .../JsonTemplateLayoutConcurrentEncodeTest.java| 6 +- .../json/JsonTemplateLayoutGcFreeTest.java | 4 +- .../JsonTemplateLayoutNullEventDelimiterTest.java | 4 +- .../template/json/JsonTemplateLayoutTest.java | 74 +-- .../log4j/layout/template/json/LogstashIT.java | 17 +-- .../layout/template/json/util/JsonReaderTest.java | 62 - .../layout/template/json/util/JsonWriterTest.java | 146 ++--- .../template/json/util/RecyclerFactoriesTest.java | 6 +- .../json/util/StringParameterParserTest.java | 84 ++-- .../json/util/TruncatingBufferedWriterTest.java| 34 ++--- .../log4j/layout/template/json/util/UrisTest.java | 16 ++- 15 files changed, 248 insertions(+), 249 deletions(-)
[logging-log4j2] branch release-2.x updated: LOG4J2-2962 Enrich "map" resolver by unifying its backend with "mdc" resolver.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new a71403e LOG4J2-2962 Enrich "map" resolver by unifying its backend with "mdc" resolver. a71403e is described below commit a71403ee2e5694a2699d68ddf09e8df6ccfc8b57 Author: Volkan Yazıcı AuthorDate: Tue Nov 17 22:54:19 2020 +0100 LOG4J2-2962 Enrich "map" resolver by unifying its backend with "mdc" resolver. --- .../layout/template/json/resolver/MapResolver.java | 74 ++--- .../template/json/resolver/MapResolverFactory.java | 2 +- ...esolver.java => ReadOnlyStringMapResolver.java} | 121 +--- .../json/resolver/ThreadContextDataResolver.java | 325 + .../template/json/JsonTemplateLayoutTest.java | 179 ++-- src/changes/changes.xml| 3 + .../asciidoc/manual/json-template-layout.adoc.vm | 260 - 7 files changed, 375 insertions(+), 589 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolver.java index f26bf86..5cc07eb 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolver.java @@ -17,75 +17,35 @@ package org.apache.logging.log4j.layout.template.json.resolver; import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.layout.template.json.util.JsonWriter; import org.apache.logging.log4j.message.MapMessage; import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.util.IndexedReadOnlyStringMap; +import org.apache.logging.log4j.util.ReadOnlyStringMap; /** - * {@link MapMessage} field resolver. + * {@link MapMessage} resolver. * - * Configuration - * - * - * config = key , [ stringified ] - * key = "key" -> string - * stringified = "stringified" -> boolean - * - * - * Examples - * - * Resolve the userRole field of the message: - * - * - * { - * "$resolver": "map", - * "key": "userRole" - * } - * + * @see ReadOnlyStringMapResolver */ -final class MapResolver implements EventResolver { - -private final String key; +final class MapResolver extends ReadOnlyStringMapResolver { -private final boolean stringified; - -static String getName() { -return "map"; +MapResolver( +final EventResolverContext context, +final TemplateResolverConfig config) { +super(context, config, MapResolver::toMap); } -MapResolver(final TemplateResolverConfig config) { -this.key = config.getString("key"); -this.stringified = config.getBoolean("stringified", false); -if (key == null) { -throw new IllegalArgumentException("missing key: " + config); -} -} - -@Override -public boolean isResolvable(final LogEvent logEvent) { -return logEvent.getMessage() instanceof MapMessage; -} - -@Override -public void resolve( -final LogEvent logEvent, -final JsonWriter jsonWriter) { +private static ReadOnlyStringMap toMap(final LogEvent logEvent) { final Message message = logEvent.getMessage(); if (!(message instanceof MapMessage)) { -jsonWriter.writeNull(); -} else { -@SuppressWarnings("unchecked") -MapMessage mapMessage = (MapMessage) message; -final IndexedReadOnlyStringMap map = mapMessage.getIndexedReadOnlyStringMap(); -final Object value = map.getValue(key); -if (stringified) { -final String stringifiedValue = String.valueOf(value); -jsonWriter.writeString(stringifiedValue); -} else { -jsonWriter.writeValue(value); -} +return null; } +@SuppressWarnings("unchecked") +final MapMessage mapMessage = (MapMessage) message; +return mapMessage.getIndexedReadOnlyStringMap(); +} + +static String getName() { +return "map"; } } diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolverFactory.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolverFactory.java index a639719..53092c9 100644 --- a/log4j-layout-template-json/src/main/java/or
[logging-log4j2] branch master updated: LOG4J2-2962 Enrich "map" resolver by unifying its backend with "mdc" resolver.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new ee1328a LOG4J2-2962 Enrich "map" resolver by unifying its backend with "mdc" resolver. ee1328a is described below commit ee1328a1f0689e9242b22a89a6ccc288573619fc Author: Volkan Yazıcı AuthorDate: Tue Nov 17 22:54:19 2020 +0100 LOG4J2-2962 Enrich "map" resolver by unifying its backend with "mdc" resolver. --- .../layout/template/json/resolver/MapResolver.java | 74 ++--- .../template/json/resolver/MapResolverFactory.java | 2 +- ...esolver.java => ReadOnlyStringMapResolver.java} | 121 +--- .../json/resolver/ThreadContextDataResolver.java | 325 + .../template/json/JsonTemplateLayoutTest.java | 179 ++-- src/changes/changes.xml| 3 + .../asciidoc/manual/json-template-layout.adoc.vm | 260 - 7 files changed, 375 insertions(+), 589 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolver.java index f26bf86..5cc07eb 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolver.java @@ -17,75 +17,35 @@ package org.apache.logging.log4j.layout.template.json.resolver; import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.layout.template.json.util.JsonWriter; import org.apache.logging.log4j.message.MapMessage; import org.apache.logging.log4j.message.Message; -import org.apache.logging.log4j.util.IndexedReadOnlyStringMap; +import org.apache.logging.log4j.util.ReadOnlyStringMap; /** - * {@link MapMessage} field resolver. + * {@link MapMessage} resolver. * - * Configuration - * - * - * config = key , [ stringified ] - * key = "key" -> string - * stringified = "stringified" -> boolean - * - * - * Examples - * - * Resolve the userRole field of the message: - * - * - * { - * "$resolver": "map", - * "key": "userRole" - * } - * + * @see ReadOnlyStringMapResolver */ -final class MapResolver implements EventResolver { - -private final String key; +final class MapResolver extends ReadOnlyStringMapResolver { -private final boolean stringified; - -static String getName() { -return "map"; +MapResolver( +final EventResolverContext context, +final TemplateResolverConfig config) { +super(context, config, MapResolver::toMap); } -MapResolver(final TemplateResolverConfig config) { -this.key = config.getString("key"); -this.stringified = config.getBoolean("stringified", false); -if (key == null) { -throw new IllegalArgumentException("missing key: " + config); -} -} - -@Override -public boolean isResolvable(final LogEvent logEvent) { -return logEvent.getMessage() instanceof MapMessage; -} - -@Override -public void resolve( -final LogEvent logEvent, -final JsonWriter jsonWriter) { +private static ReadOnlyStringMap toMap(final LogEvent logEvent) { final Message message = logEvent.getMessage(); if (!(message instanceof MapMessage)) { -jsonWriter.writeNull(); -} else { -@SuppressWarnings("unchecked") -MapMessage mapMessage = (MapMessage) message; -final IndexedReadOnlyStringMap map = mapMessage.getIndexedReadOnlyStringMap(); -final Object value = map.getValue(key); -if (stringified) { -final String stringifiedValue = String.valueOf(value); -jsonWriter.writeString(stringifiedValue); -} else { -jsonWriter.writeValue(value); -} +return null; } +@SuppressWarnings("unchecked") +final MapMessage mapMessage = (MapMessage) message; +return mapMessage.getIndexedReadOnlyStringMap(); +} + +static String getName() { +return "map"; } } diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolverFactory.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MapResolverFactory.java index a639719..53092c9 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/l
[logging-log4j2] branch release-2.x updated: Migrate JTL tests to JUnit 5.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 2aa2be7 Migrate JTL tests to JUnit 5. 2aa2be7 is described below commit 2aa2be7a8804abff189e29f530f0a7dd2204179b Author: Volkan Yazıcı AuthorDate: Wed Nov 25 10:16:21 2020 +0100 Migrate JTL tests to JUnit 5. --- log4j-layout-template-json/pom.xml | 20 +-- .../log4j/layout/template/json/EcsLayoutTest.java | 8 +- .../log4j/layout/template/json/GelfLayoutTest.java | 8 +- .../log4j/layout/template/json/JsonLayoutTest.java | 8 +- .../JsonTemplateLayoutConcurrentEncodeTest.java| 6 +- .../json/JsonTemplateLayoutGcFreeTest.java | 4 +- .../JsonTemplateLayoutNullEventDelimiterTest.java | 4 +- .../template/json/JsonTemplateLayoutTest.java | 74 +-- .../log4j/layout/template/json/LogstashIT.java | 17 ++- .../layout/template/json/util/JsonReaderTest.java | 62 - .../layout/template/json/util/JsonWriterTest.java | 146 ++--- .../template/json/util/RecyclerFactoriesTest.java | 6 +- .../json/util/StringParameterParserTest.java | 84 ++-- .../json/util/TruncatingBufferedWriterTest.java| 34 ++--- .../log4j/layout/template/json/util/UrisTest.java | 16 +-- 15 files changed, 249 insertions(+), 248 deletions(-) diff --git a/log4j-layout-template-json/pom.xml b/log4j-layout-template-json/pom.xml index a2fce5f..a398f63 100644 --- a/log4j-layout-template-json/pom.xml +++ b/log4j-layout-template-json/pom.xml @@ -177,7 +177,6 @@ org.apache.maven.plugins maven-surefire-plugin - ${maven.test.skip} **/JsonTemplateLayoutConcurrentEncodeTest.java **/JsonTemplateLayoutTest.java @@ -186,6 +185,11 @@ indeed handles everything in UTF-8 without implicitly relying on the system defaults. --> -Dfile.encoding=US-ASCII + + + true + concurrent + @@ -195,9 +199,8 @@ test - ${skipTests} - - threadLocal + + dummy **/JsonTemplateLayoutConcurrentEncodeTest.java @@ -212,8 +215,7 @@ test - ${skipTests} - + threadLocal @@ -229,8 +231,7 @@ test - ${skipTests} - + queue:supplier=java.util.concurrent.ArrayBlockingQueue.new @@ -246,8 +247,7 @@ test - ${skipTests} - + queue:supplier=org.jctools.queues.MpmcArrayQueue.new diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java index 4be0c7f..9f806f5 100644 --- a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java +++ b/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/EcsLayoutTest.java @@ -22,7 +22,7 @@ import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.DefaultConfiguration; import org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.EventTemplateAdditionalField; import org.assertj.core.api.Assertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.List; @@ -30,7 +30,7 @@ import java.util.Map; import static org.apache.logging.log4j.layout.template.json.LayoutComparisonHelpers.renderUsing; -public class EcsLayoutTest { +class EcsLayoutTest { private static final Configuration CONFIGURATION = new DefaultConfiguration(); @@ -65,13 +65,13 @@ public class EcsLayoutTest { .build(); @Test -public void test_lite_log_events() { +void test_lite_log_events() { final List logEvents = LogEventFixture.createLiteLogEvents(1_000); test(logEvents); } @Test -public void test_full_log_events() { +void test_full_log_events() { final List logEvents = LogEventFixture.createFullLogEvents(1_000); test(logEvents); } diff --git a/log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/GelfLayoutTest.java b/log4j-layout-template-json/src/test/java/
[logging-log4j2] branch master updated (ee1328a -> 2a90efd)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from ee1328a LOG4J2-2962 Enrich "map" resolver by unifying its backend with "mdc" resolver. add 2a90efd Migrate JTL tests to JUnit 5. No new revisions were added by this update. Summary of changes: log4j-layout-template-json/pom.xml | 20 +-- .../log4j/layout/template/json/EcsLayoutTest.java | 8 +- .../log4j/layout/template/json/GelfLayoutTest.java | 8 +- .../log4j/layout/template/json/JsonLayoutTest.java | 8 +- .../JsonTemplateLayoutConcurrentEncodeTest.java| 6 +- .../json/JsonTemplateLayoutGcFreeTest.java | 4 +- .../JsonTemplateLayoutNullEventDelimiterTest.java | 4 +- .../template/json/JsonTemplateLayoutTest.java | 74 +-- .../log4j/layout/template/json/LogstashIT.java | 17 ++- .../layout/template/json/util/JsonReaderTest.java | 62 - .../layout/template/json/util/JsonWriterTest.java | 146 ++--- .../template/json/util/RecyclerFactoriesTest.java | 6 +- .../json/util/StringParameterParserTest.java | 84 ++-- .../json/util/TruncatingBufferedWriterTest.java| 34 ++--- .../log4j/layout/template/json/util/UrisTest.java | 16 +-- 15 files changed, 249 insertions(+), 248 deletions(-)
[logging-log4j2] branch master updated: LOG4J2-2966 Revert the usage of ParameterizedMessage.deepToString().
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new ab8753f LOG4J2-2966 Revert the usage of ParameterizedMessage.deepToString(). ab8753f is described below commit ab8753f631b56eb2ad958041c34b32467cdbb198 Author: Volkan Yazıcı AuthorDate: Wed Dec 2 17:07:57 2020 +0100 LOG4J2-2966 Revert the usage of ParameterizedMessage.deepToString(). There are a couple of motivations for me to revert this change, but some particular highlights are as follows: - Many of the type check that is performed by deepToString() is already addressed in JsonWriter. - Usage of an external method breaks the self-containment contract of JsonWriter. - deepToString() protects against recursive collections, whereas JsonWriter doesn't. Even using deepToString() in JsonWriter isn't enough to protect it against self-referencing collections; all collection handling methods in JsonWriter needs to be adapted. Hence, rather than a code base where there is partial mitigation for this anomaly, now it is explicit that there is no built-in prevention mechanisms. This behaviour is also in line with the Java standard library, e.g., Arrays.toString(). --- .../json/resolver/MessageParameterResolver.java| 10 ++- .../json/resolver/ReadOnlyStringMapResolver.java | 6 ++-- .../template/json/resolver/TemplateResolvers.java | 3 +- .../layout/template/json/util/JsonWriter.java | 6 ++-- .../template/json/JsonTemplateLayoutTest.java | 35 -- .../asciidoc/manual/json-template-layout.adoc.vm | 16 ++ 6 files changed, 59 insertions(+), 17 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java index 866b3d1..238f523 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.layout.template.json.util.Recycler; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.ParameterConsumer; import org.apache.logging.log4j.message.ParameterVisitable; -import org.apache.logging.log4j.message.ParameterizedMessage; /** * {@link Message} parameter (i.e., {@link Message#getParameters()}) resolver. @@ -130,8 +129,7 @@ final class MessageParameterResolver implements EventResolver { } final Object parameter = parameters[i]; if (stringified) { -final String stringifiedParameter = -ParameterizedMessage.deepToString(parameter); +final String stringifiedParameter = String.valueOf(parameter); jsonWriter.writeString(stringifiedParameter); } else { jsonWriter.writeValue(parameter); @@ -144,8 +142,7 @@ final class MessageParameterResolver implements EventResolver { else { final Object parameter = parameters[index]; if (stringified) { -final String stringifiedParameter = -ParameterizedMessage.deepToString(parameter); +final String stringifiedParameter = String.valueOf(parameter); jsonWriter.writeString(stringifiedParameter); } else { jsonWriter.writeValue(parameter); @@ -206,8 +203,7 @@ final class MessageParameterResolver implements EventResolver { // Write the value. if (arrayNeeded || state.resolver.index == index) { if (state.resolver.stringified) { -final String stringifiedParameter = -ParameterizedMessage.deepToString(parameter); +final String stringifiedParameter = String.valueOf(parameter); state.jsonWriter.writeString(stringifiedParameter); } else { state.jsonWriter.writeValue(parameter); diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java index 05164c9..3735017 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json
[logging-log4j2] branch release-2.x updated: LOG4J2-2966 Revert the usage of ParameterizedMessage.deepToString().
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new b2b2068 LOG4J2-2966 Revert the usage of ParameterizedMessage.deepToString(). b2b2068 is described below commit b2b2068674664a0be28a7125de1efc15461d Author: Volkan Yazıcı AuthorDate: Wed Dec 2 17:07:57 2020 +0100 LOG4J2-2966 Revert the usage of ParameterizedMessage.deepToString(). There are a couple of motivations for me to revert this change, but some particular highlights are as follows: - Many of the type check that is performed by deepToString() is already addressed in JsonWriter. - Usage of an external method breaks the self-containment contract of JsonWriter. - deepToString() protects against recursive collections, whereas JsonWriter doesn't. Even using deepToString() in JsonWriter isn't enough to protect it against self-referencing collections; all collection handling methods in JsonWriter needs to be adapted. Hence, rather than a code base where there is partial mitigation for this anomaly, now it is explicit that there is no built-in prevention mechanisms. This behaviour is also in line with the Java standard library, e.g., Arrays.toString(). --- .../json/resolver/MessageParameterResolver.java| 10 ++- .../json/resolver/ReadOnlyStringMapResolver.java | 6 ++-- .../template/json/resolver/TemplateResolvers.java | 3 +- .../layout/template/json/util/JsonWriter.java | 6 ++-- .../template/json/JsonTemplateLayoutTest.java | 35 -- .../asciidoc/manual/json-template-layout.adoc.vm | 16 ++ 6 files changed, 59 insertions(+), 17 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java index 866b3d1..238f523 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageParameterResolver.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.layout.template.json.util.Recycler; import org.apache.logging.log4j.message.Message; import org.apache.logging.log4j.message.ParameterConsumer; import org.apache.logging.log4j.message.ParameterVisitable; -import org.apache.logging.log4j.message.ParameterizedMessage; /** * {@link Message} parameter (i.e., {@link Message#getParameters()}) resolver. @@ -130,8 +129,7 @@ final class MessageParameterResolver implements EventResolver { } final Object parameter = parameters[i]; if (stringified) { -final String stringifiedParameter = -ParameterizedMessage.deepToString(parameter); +final String stringifiedParameter = String.valueOf(parameter); jsonWriter.writeString(stringifiedParameter); } else { jsonWriter.writeValue(parameter); @@ -144,8 +142,7 @@ final class MessageParameterResolver implements EventResolver { else { final Object parameter = parameters[index]; if (stringified) { -final String stringifiedParameter = -ParameterizedMessage.deepToString(parameter); +final String stringifiedParameter = String.valueOf(parameter); jsonWriter.writeString(stringifiedParameter); } else { jsonWriter.writeValue(parameter); @@ -206,8 +203,7 @@ final class MessageParameterResolver implements EventResolver { // Write the value. if (arrayNeeded || state.resolver.index == index) { if (state.resolver.stringified) { -final String stringifiedParameter = -ParameterizedMessage.deepToString(parameter); +final String stringifiedParameter = String.valueOf(parameter); state.jsonWriter.writeString(stringifiedParameter); } else { state.jsonWriter.writeValue(parameter); diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/ReadOnlyStringMapResolver.java index 05164c9..3735017 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template
[logging-log4j2] branch master updated: Close RAFMs in RandomAccessFileManagerTest to avoid test failures on Windows.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/master by this push: new 38df09d Close RAFMs in RandomAccessFileManagerTest to avoid test failures on Windows. 38df09d is described below commit 38df09dedcf2ad187803f359b2c8176fe29e1aab Author: Volkan Yazıcı AuthorDate: Tue Nov 10 16:40:11 2020 +0100 Close RAFMs in RandomAccessFileManagerTest to avoid test failures on Windows. This fix is adapted from Gary Gregory's 6797db0e on release-2.x. --- .../core/appender/RandomAccessFileManagerTest.java | 75 +++--- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java index 6227f37..821727b 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java @@ -45,15 +45,15 @@ public class RandomAccessFileManagerTest { final File file = new File(tempDir, "testWrite_multiplesOfBufferSize.bin"); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); -final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), -os, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true); - -final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3; -final byte[] data = new byte[size]; -manager.write(data); // no buffer overflow exception - -// all data is written if exceeds buffer size -assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3, raf.length()); +try (final RandomAccessFileManager manager = new RandomAccessFileManager( +null, raf, file.getName(), os, +RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true)) { +final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3; +final byte[] data = new byte[size]; +manager.write(data); // no buffer overflow exception +// all data is written if exceeds buffer size +assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3, raf.length()); +} } } @@ -67,17 +67,16 @@ public class RandomAccessFileManagerTest { final File file = new File(tempDir, "testWrite_dataExceedingBufferSize.bin"); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); -final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), -os, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true); - final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1; -final byte[] data = new byte[size]; -manager.write(data); // no exception -// all data is written if exceeds buffer size -assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1, raf.length()); - -manager.flush(); -assertEquals(size, raf.length()); // all data written to file now +try (final RandomAccessFileManager manager = new RandomAccessFileManager( +null, raf, file.getName(), os, +RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true)) { +final byte[] data = new byte[size]; +manager.write(data); // no exception +// all data is written if exceeds buffer size +assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1, raf.length()); +assertEquals(size, raf.length()); // all data written to file now +} } } @@ -88,12 +87,11 @@ public class RandomAccessFileManagerTest { final OutputStream os = NullOutputStream.getInstance(); final int bufferSize = 4 * 1024; assertNotEquals(bufferSize, RandomAccessFileManager.DEFAULT_BUFFER_SIZE); - -final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), -os, bufferSize, null, null, true); - -// check the resulting buffer size is what was requested -assertEquals(bufferSize, manager.getBufferSize()); +try (final RandomAccessFileManager manager = new RandomAccessFileManager( +null, raf, fi
[logging-log4j2] branch master updated (a42def9 -> d8c8691)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. from a42def9 LOG4J2-2850 Fix indentation in LocalizedMessageFactoryTest. new 749ef13 Improve JTL TemplateResolver docs. new d71e0cf Remove constants in JsonTemplateLayoutDefaults to allow updates at runtime. new d8c8691 LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks. 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: .../logging/log4j/kafka/appender/KafkaManager.java | 4 +- .../KafkaManagerProducerThreadLeakTest.java| 46 ++ .../template/json/JsonTemplateLayoutDefaults.java | 178 ++--- .../template/json/resolver/TemplateResolver.java | 27 src/changes/changes.xml| 3 + 5 files changed, 131 insertions(+), 127 deletions(-) create mode 100644 log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/appender/KafkaManagerProducerThreadLeakTest.java
[logging-log4j2] 01/03: Improve JTL TemplateResolver docs.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 749ef1373749480fe1a0cfd84100d7e3d9b89d73 Author: Volkan Yazıcı AuthorDate: Wed Nov 11 16:34:38 2020 +0100 Improve JTL TemplateResolver docs. --- .../template/json/resolver/TemplateResolver.java | 27 ++ 1 file changed, 27 insertions(+) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.java index 5db3813..62ce41d 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolver.java @@ -21,20 +21,47 @@ import org.apache.logging.log4j.layout.template.json.util.JsonWriter; @FunctionalInterface public interface TemplateResolver { +/** + * Indicates if the resolution should be appended to the parent JSON object. + * + * For instance, {@link ThreadContextDataResolver}, i.e., MDC resolver, + * uses this flag to indicate whether the contents should be appended to the + * parent JSON object or not. + */ default boolean isFlattening() { return false; } +/** + * Indicates if the resolver if applicable at all. + * + * For instance, the source line resolver can be short-circuited using this + * check if the location information is disabled in the layout configuration. + */ default boolean isResolvable() { return true; } +/** + * Indicates if the resolver if applicable for the given {@code value}. + * + * For instance, the stack trace resolver can be short-circuited using this + * check if the stack traces are disabled in the layout configuration. + */ default boolean isResolvable(V value) { return true; } +/** + * Resolves the given {@code value} using the provided {@link JsonWriter}. + */ void resolve(V value, JsonWriter jsonWriter); +/** + * Resolves the given {@code value} using the provided {@link JsonWriter}. + * + * @param succeedingEntry false, if this is the first element in a collection; true, otherwise + */ default void resolve(V value, JsonWriter jsonWriter, boolean succeedingEntry) { resolve(value, jsonWriter); }
[logging-log4j2] 02/03: Remove constants in JsonTemplateLayoutDefaults to allow updates at runtime.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit d71e0cf5784bbe9afeef9f8f5e8d0c97eb6ca7f5 Author: Volkan Yazıcı AuthorDate: Wed Nov 11 16:35:24 2020 +0100 Remove constants in JsonTemplateLayoutDefaults to allow updates at runtime. --- .../template/json/JsonTemplateLayoutDefaults.java | 178 ++--- 1 file changed, 52 insertions(+), 126 deletions(-) diff --git a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutDefaults.java b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutDefaults.java index 9896c1e..4f417ee 100644 --- a/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutDefaults.java +++ b/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/JsonTemplateLayoutDefaults.java @@ -29,71 +29,7 @@ public enum JsonTemplateLayoutDefaults {; private static final PropertiesUtil PROPERTIES = PropertiesUtil.getProperties(); -private static final Charset CHARSET = readCharset(); - -private static final boolean LOCATION_INFO_ENABLED = -PROPERTIES.getBooleanProperty( -"log4j.layout.jsonTemplate.locationInfoEnabled", -false); - -private static final boolean STACK_TRACE_ENABLED = -PROPERTIES.getBooleanProperty( -"log4j.layout.jsonTemplate.stackTraceEnabled", -true); - -private static final String TIMESTAMP_FORMAT_PATTERN = -PROPERTIES.getStringProperty( -"log4j.layout.jsonTemplate.timestampFormatPattern", -"-MM-dd'T'HH:mm:ss.SSSZZZ"); - -private static final TimeZone TIME_ZONE = readTimeZone(); - -private static final Locale LOCALE = readLocale(); - -private static final String EVENT_TEMPLATE = -PROPERTIES.getStringProperty( -"log4j.layout.jsonTemplate.eventTemplate"); - -private static final String EVENT_TEMPLATE_URI = -PROPERTIES.getStringProperty( -"log4j.layout.jsonTemplate.eventTemplateUri", -"classpath:EcsLayout.json"); - -private static final String STACK_TRACE_ELEMENT_TEMPLATE = -PROPERTIES.getStringProperty( -"log4j.layout.jsonTemplate.stackTraceElementTemplate"); - -private static final String STACK_TRACE_ELEMENT_TEMPLATE_URI = -PROPERTIES.getStringProperty( -"log4j.layout.jsonTemplate.stackTraceElementTemplateUri", -"classpath:StackTraceElementLayout.json"); - -private static final String MDC_KEY_PATTERN = - PROPERTIES.getStringProperty("log4j.layout.jsonTemplate.mdcKeyPattern"); - -private static final String NDC_PATTERN = - PROPERTIES.getStringProperty("log4j.layout.jsonTemplate.ndcPattern"); - -private static final String EVENT_DELIMITER = -PROPERTIES.getStringProperty( -"log4j.layout.jsonTemplate.eventDelimiter", -System.lineSeparator()); - -private static final boolean NULL_EVENT_DELIMITER_ENABLED = -PROPERTIES.getBooleanProperty( -"log4j.layout.jsonTemplate.nullEventDelimiterEnabled", -false); - -private static final int MAX_STRING_LENGTH = readMaxStringLength(); - -private static final String TRUNCATED_STRING_SUFFIX = -PROPERTIES.getStringProperty( -"log4j.layout.jsonTemplate.truncatedStringSuffix", -"…"); - -private static final RecyclerFactory RECYCLER_FACTORY = readRecyclerFactory(); - -private static Charset readCharset() { +public static Charset getCharset() { final String charsetName = PROPERTIES.getStringProperty("log4j.layout.jsonTemplate.charset"); return charsetName != null @@ -101,7 +37,25 @@ public enum JsonTemplateLayoutDefaults {; : StandardCharsets.UTF_8; } -private static TimeZone readTimeZone() { +public static boolean isLocationInfoEnabled() { +return PROPERTIES.getBooleanProperty( +"log4j.layout.jsonTemplate.locationInfoEnabled", +false); +} + +public static boolean isStackTraceEnabled() { +return PROPERTIES.getBooleanProperty( +"log4j.layout.jsonTemplate.stackTraceEnabled", +true); +} + +public static String getTimestampFormatPattern() { +return PROPERTIES.getStringProperty( +
[logging-log4j2] 03/03: LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit d8c8691917763451aa43a8d00f147d2c6fc799b1 Author: Volkan Yazıcı AuthorDate: Thu Nov 12 17:46:20 2020 +0100 LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks. --- .../logging/log4j/kafka/appender/KafkaManager.java | 4 +- .../KafkaManagerProducerThreadLeakTest.java| 46 ++ src/changes/changes.xml| 3 ++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/log4j-kafka/src/main/java/org/apache/logging/log4j/kafka/appender/KafkaManager.java b/log4j-kafka/src/main/java/org/apache/logging/log4j/kafka/appender/KafkaManager.java index a4e4ddb..db03167 100644 --- a/log4j-kafka/src/main/java/org/apache/logging/log4j/kafka/appender/KafkaManager.java +++ b/log4j-kafka/src/main/java/org/apache/logging/log4j/kafka/appender/KafkaManager.java @@ -153,7 +153,9 @@ public class KafkaManager extends AbstractManager { } public void startup() { -producer = producerFactory.newKafkaProducer(config); +if (producer == null) { +producer = producerFactory.newKafkaProducer(config); +} } public String getTopic() { diff --git a/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/appender/KafkaManagerProducerThreadLeakTest.java b/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/appender/KafkaManagerProducerThreadLeakTest.java new file mode 100644 index 000..2ebf60f --- /dev/null +++ b/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/appender/KafkaManagerProducerThreadLeakTest.java @@ -0,0 +1,46 @@ +package org.apache.logging.log4j.kafka.appender; + +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.junit.LoggerContextSource; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Verifies that restarting the {@link LoggerContext} doesn't cause + * {@link KafkaManager} to leak threads. + * + * @see https://issues.apache.org/jira/browse/LOG4J2-2916;>LOG4J2-2916 + */ +@LoggerContextSource("KafkaAppenderTest.xml") +class KafkaManagerProducerThreadLeakTest { + +@Test +void context_restart_shouldnt_leak_producer_threads(final LoggerContext context) { + +// Determine the initial number of threads. +final int initialThreadCount = kafkaProducerThreadCount(); + +// Perform context restarts. +final int contextRestartCount = 3; +for (int i = 0; i < contextRestartCount; i++) { +context.reconfigure(); +} + +// Verify the final thread count. +final int lastThreadCount = kafkaProducerThreadCount(); +assertEquals(initialThreadCount, lastThreadCount); + +} + +private static int kafkaProducerThreadCount() { +final long threadCount = Thread +.getAllStackTraces() +.keySet() +.stream() +.filter(thread -> thread.getName().startsWith("kafka-producer")) +.count(); +return Math.toIntExact(threadCount); +} + +} diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 313a922..e191147 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -31,6 +31,9 @@ - "remove" - Removed --> + +Avoid redundant Kafka producer instantiation causing thread leaks. + Update jetty-util from 8.2.0.v20160908 to 9.4.31.v20200723.
[logging-log4j2] branch master updated (d8c8691 -> 97db574)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. discard d8c8691 LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks. new 97db574 LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks. This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (d8c8691) \ N -- N -- N refs/heads/master (97db574) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 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: .../appender/KafkaManagerProducerThreadLeakTest.java | 19 +++ 1 file changed, 19 insertions(+)
[logging-log4j2] 01/01: LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit 97db5743a3b10e9017bf70794d6275b21553dd44 Author: Volkan Yazıcı AuthorDate: Thu Nov 12 17:46:20 2020 +0100 LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks. --- .../logging/log4j/kafka/appender/KafkaManager.java | 4 +- .../KafkaManagerProducerThreadLeakTest.java| 65 ++ src/changes/changes.xml| 3 + 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/log4j-kafka/src/main/java/org/apache/logging/log4j/kafka/appender/KafkaManager.java b/log4j-kafka/src/main/java/org/apache/logging/log4j/kafka/appender/KafkaManager.java index a4e4ddb..db03167 100644 --- a/log4j-kafka/src/main/java/org/apache/logging/log4j/kafka/appender/KafkaManager.java +++ b/log4j-kafka/src/main/java/org/apache/logging/log4j/kafka/appender/KafkaManager.java @@ -153,7 +153,9 @@ public class KafkaManager extends AbstractManager { } public void startup() { -producer = producerFactory.newKafkaProducer(config); +if (producer == null) { +producer = producerFactory.newKafkaProducer(config); +} } public String getTopic() { diff --git a/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/appender/KafkaManagerProducerThreadLeakTest.java b/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/appender/KafkaManagerProducerThreadLeakTest.java new file mode 100644 index 000..73fcf62 --- /dev/null +++ b/log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/appender/KafkaManagerProducerThreadLeakTest.java @@ -0,0 +1,65 @@ +/* + * 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.logging.log4j.kafka.appender; + +import org.apache.logging.log4j.categories.Appenders; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.junit.LoggerContextSource; +import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Verifies that restarting the {@link LoggerContext} doesn't cause + * {@link KafkaManager} to leak threads. + * + * @see https://issues.apache.org/jira/browse/LOG4J2-2916;>LOG4J2-2916 + */ +@Category(Appenders.Kafka.class) +@LoggerContextSource("KafkaAppenderTest.xml") +class KafkaManagerProducerThreadLeakTest { + +@Test +void context_restart_shouldnt_leak_producer_threads(final LoggerContext context) { + +// Determine the initial number of threads. +final int initialThreadCount = kafkaProducerThreadCount(); + +// Perform context restarts. +final int contextRestartCount = 3; +for (int i = 0; i < contextRestartCount; i++) { +context.reconfigure(); +} + +// Verify the final thread count. +final int lastThreadCount = kafkaProducerThreadCount(); +assertEquals(initialThreadCount, lastThreadCount); + +} + +private static int kafkaProducerThreadCount() { +final long threadCount = Thread +.getAllStackTraces() +.keySet() +.stream() +.filter(thread -> thread.getName().startsWith("kafka-producer")) +.count(); +return Math.toIntExact(threadCount); +} + +} diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 313a922..e191147 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -31,6 +31,9 @@ - "remove" - Removed --> + +Avoid redundant Kafka producer instantiation causing thread leaks. + Update jetty-util from 8.2.0.v20160908 to 9.4.31.v20200723.
[logging-log4j2] branch release-2.x updated: LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 4bd4b5e LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks. 4bd4b5e is described below commit 4bd4b5efe2cd1e1da7ef4c84cd205aba0d1187b4 Author: Volkan Yazici AuthorDate: Thu Nov 12 23:07:12 2020 +0100 LOG4J2-2916 Avoid redundant Kafka producer instantiation causing thread leaks. --- .../core/appender/mom/kafka/KafkaManager.java | 4 +- .../kafka/KafkaManagerProducerThreadLeakTest.java | 66 ++ .../KafkaManagerProducerThreadLeakTest.xml | 31 ++ src/changes/changes.xml| 3 + 4 files changed, 103 insertions(+), 1 deletion(-) diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManager.java index 394cef0..a03cbb1 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManager.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManager.java @@ -138,7 +138,9 @@ public class KafkaManager extends AbstractManager { } public void startup() { - producer = producerFactory.newKafkaProducer(config); + if (producer == null) { + producer = producerFactory.newKafkaProducer(config); + } } public String getTopic() { diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManagerProducerThreadLeakTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManagerProducerThreadLeakTest.java new file mode 100644 index 000..3158e91 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaManagerProducerThreadLeakTest.java @@ -0,0 +1,66 @@ +/* + * 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.logging.log4j.core.appender.mom.kafka; + +import org.apache.logging.log4j.categories.Appenders; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.junit.LoggerContextSource; +import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Verifies that restarting the {@link LoggerContext} doesn't cause + * {@link KafkaManager} to leak threads. + * + * @see https://issues.apache.org/jira/browse/LOG4J2-2916;>LOG4J2-2916 + */ +@Category(Appenders.Kafka.class) +@LoggerContextSource("KafkaManagerProducerThreadLeakTest.xml") +class KafkaManagerProducerThreadLeakTest { + +@Test +void context_restart_shouldnt_leak_producer_threads(final LoggerContext context) { + +// Determine the initial number of threads. +final int initialThreadCount = kafkaProducerThreadCount(); + +// Perform context restarts. +final int contextRestartCount = 3; +for (int i = 0; i < contextRestartCount; i++) { +context.reconfigure(); +} + +// Verify the final thread count. +final int lastThreadCount = kafkaProducerThreadCount(); +assertEquals(initialThreadCount, lastThreadCount); + +} + +private static int kafkaProducerThreadCount() { +final long threadCount = Thread +.getAllStackTraces() +.keySet() +.stream() +.filter(thread -> thread.getName().startsWith("kafka-producer")) +.count(); +return Math.toIntExact(threadCount); +} + +} diff --git a/log4j-core/src/test/resources/KafkaManagerProducerThreadLeakTest.xml b/log4j-core/src/test/resources/KafkaManagerProducerThreadLeakTest.xml new file mode 100644 index 000..09ca852 --- /dev/null +++ b/log4j-core/src/test/resources/KafkaManagerProducerThreadLeakTest.xml @@ -0,0 +1,31 @@ + + + +
[logging-log4j2] 01/01: Suppress revapi complaints regarding JTL.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git commit b4dc0e2af8e0815f10367807f57cc0e01730749f Author: Volkan Yazici AuthorDate: Thu Nov 19 17:27:07 2020 +0100 Suppress revapi complaints regarding JTL. --- log4j-layout-template-json/revapi.json | 366 + 1 file changed, 366 insertions(+) diff --git a/log4j-layout-template-json/revapi.json b/log4j-layout-template-json/revapi.json index c24b6fc..a259b85 100644 --- a/log4j-layout-template-json/revapi.json +++ b/log4j-layout-template-json/revapi.json @@ -42,6 +42,372 @@ "code": "java.method.removed", "old": "method java.lang.String org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults::getNdcPattern()", "justification": "Removed unused property getter." + }, + { +"code": "java.method.removed", +"old": "method int java.lang.Enum>>::compareTo(E) @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method java.lang.Class java.lang.Enum>>::getDeclaringClass() @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method java.lang.String java.lang.Enum>>::name() @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method int java.lang.Enum>>::ordinal() @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.class.noLongerImplementsInterface", +"old": "enum org.apache.logging.log4j.layout.template.json.util.Uris", +"new": "class org.apache.logging.log4j.layout.template.json.util.Uris", +"interface": "java.lang.Comparable", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.class.noLongerImplementsInterface", +"old": "enum org.apache.logging.log4j.layout.template.json.util.Uris", +"new": "class org.apache.logging.log4j.layout.template.json.util.Uris", +"interface": "java.io.Serializable", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method >> T java.lang.Enum>>::valueOf(java.lang.Class, java.lang.String) @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults::valueOf(java.lang.String)", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults[] org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults::values()", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.class.noLongerInheritsFromClass", +"old": "enum org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"new": "class org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.class.kindChanged", +"old": &quo
[logging-log4j2] branch release-2.x updated (0e7a29b -> b4dc0e2)
This is an automated email from the ASF dual-hosted git repository. vy pushed a change to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git. discard 0e7a29b Suppress revapi complaints regarding JTL. new b4dc0e2 Suppress revapi complaints regarding JTL. This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (0e7a29b) \ N -- N -- N refs/heads/release-2.x (b4dc0e2) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omit" are not gone; other references still refer to them. Any revisions marked "discard" are gone forever. The 1 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: log4j-layout-template-json/revapi.json | 332 + 1 file changed, 332 insertions(+)
[logging-log4j2] branch release-2.x updated: Suppress revapi complaints regarding JTL.
This is an automated email from the ASF dual-hosted git repository. vy pushed a commit to branch release-2.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git The following commit(s) were added to refs/heads/release-2.x by this push: new 0e7a29b Suppress revapi complaints regarding JTL. 0e7a29b is described below commit 0e7a29b6055b57e5ccf566243a45112d01a74de1 Author: Volkan Yazici AuthorDate: Thu Nov 19 17:27:07 2020 +0100 Suppress revapi complaints regarding JTL. --- log4j-layout-template-json/revapi.json | 34 ++ 1 file changed, 34 insertions(+) diff --git a/log4j-layout-template-json/revapi.json b/log4j-layout-template-json/revapi.json index c24b6fc..b804312 100644 --- a/log4j-layout-template-json/revapi.json +++ b/log4j-layout-template-json/revapi.json @@ -42,6 +42,40 @@ "code": "java.method.removed", "old": "method java.lang.String org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults::getNdcPattern()", "justification": "Removed unused property getter." + }, + { +"code": "java.method.removed", +"old": "method int java.lang.Enum>>::compareTo(E) @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method java.lang.Class java.lang.Enum>>::getDeclaringClass() @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method java.lang.String java.lang.Enum>>::name() @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.method.removed", +"old": "method int java.lang.Enum>>::ordinal() @ org.apache.logging.log4j.layout.template.json.JsonTemplateLayoutDefaults", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.class.noLongerImplementsInterface", +"old": "enum org.apache.logging.log4j.layout.template.json.util.Uris", +"new": "class org.apache.logging.log4j.layout.template.json.util.Uris", +"interface": "java.lang.Comparable", +"justification": "Replaced 'enum' singletons with 'final class'es." + }, + { +"code": "java.class.noLongerImplementsInterface", +"old": "enum org.apache.logging.log4j.layout.template.json.util.Uris", +"new": "class org.apache.logging.log4j.layout.template.json.util.Uris", +"interface": "java.io.Serializable", +"justification": "Replaced 'enum' singletons with 'final class'es." } ] }