From f682332d53db33da031a572706a71d7d56b79e5f Mon Sep 17 00:00:00 2001 From: Milenko Supic Date: Fri, 18 Aug 2023 16:11:24 +0200 Subject: [PATCH 1/6] Additional metadata for ch.qos.logback:logback-classic:1.4.1 --- .../logback-classic/1.4.1/reflect-config.json | 142 ++++++++++++++++++ .../org/graalvm/logback/LogbackTests.java | 40 +++++ .../org/graalvm/logback/util/LayoutTags.java | 33 ++++ 3 files changed, 215 insertions(+) create mode 100644 tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java diff --git a/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json b/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json index cbeb83750..e003f036c 100644 --- a/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json +++ b/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json @@ -11,6 +11,76 @@ } ] }, + { + "name": "ch.qos.logback.classic.html.HTMLLayout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "ch.qos.logback.classic.html.UrlCssBuilder", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setUrl", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.classic.layout.TTLLLayout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "ch.qos.logback.classic.log4j.XMLLayout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setLocationInfo", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "setProperties", + "parameterTypes": [ + "boolean" + ] + } + ] + }, { "name": "ch.qos.logback.classic.pattern.CallerDataConverter", "condition": { @@ -350,6 +420,20 @@ } ] }, + { + "name": "ch.qos.logback.core.Layout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, { "name": "ch.qos.logback.core.OutputStreamAppender", "condition": { @@ -369,7 +453,18 @@ "condition": { "typeReachable": "ch.qos.logback.core.joran.util.PropertySetter" }, + "queryAllPublicMethods": true, "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setLayout", + "parameterTypes": [ + "ch.qos.logback.core.Layout" + ] + }, { "name": "setParent", "parameterTypes": [ @@ -378,6 +473,53 @@ } ] }, + { + "name": "ch.qos.logback.core.html.CssBuilder", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.html.HTMLLayoutBase", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "methods": [ + { + "name": "setCssBuilder", + "parameterTypes": [ + "ch.qos.logback.core.html.CssBuilder" + ] + }, + { + "name": "setPattern", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.layout.EchoLayout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, { "name": "ch.qos.logback.core.pattern.IdentityCompositeConverter", "condition": { diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java index 7da5614c3..f37fad5e9 100644 --- a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java @@ -6,25 +6,31 @@ */ package org.graalvm.logback; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; import java.util.stream.Stream; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.PatternLayout; import ch.qos.logback.classic.encoder.PatternLayoutEncoder; +import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.ConsoleAppender; import ch.qos.logback.core.joran.util.PropertySetter; import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache; +import org.graalvm.logback.util.LayoutTags; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -34,6 +40,22 @@ public class LogbackTests { private static final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); + private static final Map layoutTagMap = new HashMap<>(); + static { + layoutTagMap.put("echoLayout", LayoutTags.ECHO_TAG); + layoutTagMap.put("htmlLayout", LayoutTags.HTML_TAG); + layoutTagMap.put("ttllLayout", LayoutTags.TTLL_TAG); + layoutTagMap.put("xmlLayout", LayoutTags.XML_TAG); + } + + private static final Map layoutResultMap = new HashMap<>(); + static { + layoutResultMap.put("echoLayout", "[INFO] test info message"); + layoutResultMap.put("htmlLayout", "test info message"); + layoutResultMap.put("ttllLayout", "INFO ROOT - test info message"); + layoutResultMap.put("xmlLayout", "test info message"); + } + private final PrintStream systemOut = System.out; private ByteArrayOutputStream outputStreamCaptor; @@ -46,6 +68,24 @@ public void setUp() { System.setOut(new PrintStream(this.outputStreamCaptor)); } + @ParameterizedTest + @ValueSource(strings = {"echoLayout", "htmlLayout", "ttllLayout", "xmlLayout"}) + void testLayouts(String layoutName) throws Exception { + LoggerContext testLoggerContext = new LoggerContext(); + + JoranConfigurator joranConfigurator = new JoranConfigurator(); + joranConfigurator.setContext(testLoggerContext); + + String configXml = LayoutTags.CONFIG_TAG.formatted(layoutTagMap.get(layoutName)); + joranConfigurator.doConfigure(new ByteArrayInputStream(configXml.getBytes())); + + Logger testLogger = testLoggerContext.getLogger(Logger.ROOT_LOGGER_NAME); + testLogger.info("test info message"); + + String loggedMessage = outputStreamCaptor.toString(); + assertThat(loggedMessage).contains(layoutResultMap.get(layoutName)); + } + @Test void debugMessageLoggedViaExternalConfig() { Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME); diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java new file mode 100644 index 000000000..493672cd7 --- /dev/null +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java @@ -0,0 +1,33 @@ +package org.graalvm.logback.util; + +public class LayoutTags { + + public static final String CONFIG_TAG = """ + + + + %s + + + + + + + """; + + public static final String ECHO_TAG = ""; + + public static final String HTML_TAG = """ + + %msg + test-url + """; + + public static final String TTLL_TAG = ""; + + public static final String XML_TAG = """ + + true + true + """; +} From d2c397c7191aaf9ce8652f79864b71add7aca32a Mon Sep 17 00:00:00 2001 From: Milenko Supic Date: Fri, 18 Aug 2023 16:24:02 +0200 Subject: [PATCH 2/6] Added Copyright section --- .../src/test/java/org/graalvm/logback/util/LayoutTags.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java index 493672cd7..ff39152c6 100644 --- a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java @@ -1,3 +1,9 @@ +/* + * Copyright and related rights waived via CC0 + * + * You should have received a copy of the CC0 legalcode along with this + * work. If not, see . + */ package org.graalvm.logback.util; public class LayoutTags { From b523d40a18db8b5903daf532740f3984e1b8ded3 Mon Sep 17 00:00:00 2001 From: Milenko Supic Date: Mon, 28 Aug 2023 10:55:18 +0200 Subject: [PATCH 3/6] Added metadata for file appenders --- .../logback-classic/1.4.1/reflect-config.json | 271 ++++++++++++++++++ .../org/graalvm/logback/LogbackTests.java | 74 ++++- .../graalvm/logback/util/AppenderTags.java | 54 ++++ .../org/graalvm/logback/util/LayoutTags.java | 6 + 4 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/AppenderTags.java diff --git a/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json b/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json index e003f036c..b02a1c5b7 100644 --- a/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json +++ b/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json @@ -1,4 +1,17 @@ [ + { + "name": "ch.qos.logback.classic.PatternLayout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, { "name": "ch.qos.logback.classic.encoder.PatternLayoutEncoder", "condition": { @@ -420,6 +433,43 @@ } ] }, + { + "name": "ch.qos.logback.core.FileAppender", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setAppend", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "setFile", + "parameterTypes": [ + "java.lang.String" + ] + }, + { + "name": "setPrudent", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, { "name": "ch.qos.logback.core.Layout", "condition": { @@ -445,6 +495,12 @@ "parameterTypes": [ "ch.qos.logback.core.encoder.Encoder" ] + }, + { + "name": "setImmediateFlush", + "parameterTypes": [ + "boolean" + ] } ] }, @@ -532,6 +588,26 @@ } ] }, + { + "name": "ch.qos.logback.core.pattern.PatternLayoutBase", + "condition": { + "typeReachable": "ch.qos.logback.core.model.processor.ImplicitModelHandler" + }, + "methods": [ + { + "name": "setOutputPatternAsHeader", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "setPattern", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, { "name": "ch.qos.logback.core.pattern.PatternLayoutEncoderBase", "condition": { @@ -749,5 +825,200 @@ "parameterTypes": [] } ] + }, + { + "name": "ch.qos.logback.core.rolling.RollingFileAppender", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setFile", + "parameterTypes": [ + "java.lang.String" + ] + }, + { + "name": "setRollingPolicy", + "parameterTypes": [ + "ch.qos.logback.core.rolling.RollingPolicy" + ] + }, + { + "name": "setTriggeringPolicy", + "parameterTypes": [ + "ch.qos.logback.core.rolling.TriggeringPolicy" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.RollingPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.RollingPolicyBase", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "setFileNamePattern", + "parameterTypes": [ + "java.lang.String" + ] + }, + { + "name": "setParent", + "parameterTypes": [ + "ch.qos.logback.core.FileAppender" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setMaxFileSize", + "parameterTypes": [ + "ch.qos.logback.core.util.FileSize" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setMaxFileSize", + "parameterTypes": [ + "ch.qos.logback.core.util.FileSize" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.TimeBasedRollingPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "setCleanHistoryOnStart", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "setMaxHistory", + "parameterTypes": [ + "int" + ] + }, + { + "name": "setTotalSizeCap", + "parameterTypes": [ + "ch.qos.logback.core.util.FileSize" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.TriggeringPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.helper.DateTokenConverter", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.helper.IntegerTokenConverter", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "ch.qos.logback.core.spi.ContextAware", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.util.FileSize", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] } ] diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java index f37fad5e9..0f6a926ae 100644 --- a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java @@ -8,8 +8,14 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; import java.io.PrintStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.stream.Stream; @@ -23,10 +29,14 @@ import ch.qos.logback.core.ConsoleAppender; import ch.qos.logback.core.joran.util.PropertySetter; import ch.qos.logback.core.joran.util.beans.BeanDescriptionCache; +import org.graalvm.logback.util.AppenderTags; import org.graalvm.logback.util.LayoutTags; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -36,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class LogbackTests { private static final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); @@ -44,6 +55,7 @@ public class LogbackTests { static { layoutTagMap.put("echoLayout", LayoutTags.ECHO_TAG); layoutTagMap.put("htmlLayout", LayoutTags.HTML_TAG); + layoutTagMap.put("patternLayout", LayoutTags.PATTERN_TAG); layoutTagMap.put("ttllLayout", LayoutTags.TTLL_TAG); layoutTagMap.put("xmlLayout", LayoutTags.XML_TAG); } @@ -52,6 +64,7 @@ public class LogbackTests { static { layoutResultMap.put("echoLayout", "[INFO] test info message"); layoutResultMap.put("htmlLayout", "test info message"); + layoutResultMap.put("patternLayout", "#logback.classic pattern: %msg\ntest info message"); layoutResultMap.put("ttllLayout", "INFO ROOT - test info message"); layoutResultMap.put("xmlLayout", "test info message"); } @@ -60,6 +73,27 @@ public class LogbackTests { private ByteArrayOutputStream outputStreamCaptor; + private Path tempDirPath; + + @BeforeAll + void beforeAll() throws IOException { + tempDirPath = Files.createTempDirectory("logback-metadata-test"); + } + + @AfterAll + void afterAll() { + if (tempDirPath != null) { + try { + Files.walk(tempDirPath) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + @BeforeEach public void setUp() { MDC.put("test", "GraalVM"); @@ -69,7 +103,7 @@ public void setUp() { } @ParameterizedTest - @ValueSource(strings = {"echoLayout", "htmlLayout", "ttllLayout", "xmlLayout"}) + @ValueSource(strings = {"echoLayout", "htmlLayout", "patternLayout", "ttllLayout", "xmlLayout"}) void testLayouts(String layoutName) throws Exception { LoggerContext testLoggerContext = new LoggerContext(); @@ -86,6 +120,44 @@ void testLayouts(String layoutName) throws Exception { assertThat(loggedMessage).contains(layoutResultMap.get(layoutName)); } + @Test + void testFileAppender() throws Exception { + LoggerContext testLoggerContext = new LoggerContext(); + + JoranConfigurator joranConfigurator = new JoranConfigurator(); + joranConfigurator.setContext(testLoggerContext); + + String filePath = tempDirPath + "/log.txt"; + String filesTag = AppenderTags.FILE_TAG.formatted(filePath); + String configXml = AppenderTags.CONFIG_TAG.formatted(filesTag); + joranConfigurator.doConfigure(new ByteArrayInputStream(configXml.getBytes())); + + Logger testLogger = testLoggerContext.getLogger(Logger.ROOT_LOGGER_NAME); + testLogger.info("test info message"); + + String loggedMessage = Files.readAllLines(Paths.get(filePath)).get(0); + assertThat(loggedMessage).isEqualTo("test info message"); + } + + @Test + void testRollingFileAppender() throws Exception { + LoggerContext testLoggerContext = new LoggerContext(); + + JoranConfigurator joranConfigurator = new JoranConfigurator(); + joranConfigurator.setContext(testLoggerContext); + + String filePath = tempDirPath + "/rolling-log.txt"; + String filesTag = AppenderTags.ROLLING_FILE_TAG.formatted(filePath); + String configXml = AppenderTags.CONFIG_TAG.formatted(filesTag); + joranConfigurator.doConfigure(new ByteArrayInputStream(configXml.getBytes())); + + Logger testLogger = testLoggerContext.getLogger(Logger.ROOT_LOGGER_NAME); + testLogger.info("test info message"); + + String loggedMessage = Files.readAllLines(Paths.get(filePath)).get(0); + assertThat(loggedMessage).isEqualTo("test info message"); + } + @Test void debugMessageLoggedViaExternalConfig() { Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME); diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/AppenderTags.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/AppenderTags.java new file mode 100644 index 000000000..51106ebd8 --- /dev/null +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/AppenderTags.java @@ -0,0 +1,54 @@ +/* + * Copyright and related rights waived via CC0 + * + * You should have received a copy of the CC0 legalcode along with this + * work. If not, see . + */ +package org.graalvm.logback.util; + +public class AppenderTags { + + public static final String CONFIG_TAG = """ + + %s + + + + + """; + + public static final String FILE_TAG = """ + + %s + true + false + + %%msg + + true + + """; + + public static final String ROLLING_FILE_TAG = """ + + %s + + rolling-log-%%d{yyyy-MM-dd}.%%i.txt + 100MB + 60 + 20GB + false + + + 100MB + + true + false + + %%msg + + true + + """; + +} diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java index ff39152c6..153f11738 100644 --- a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java @@ -29,6 +29,12 @@ public class LayoutTags { test-url """; + public static final String PATTERN_TAG = """ + + %msg + true + """; + public static final String TTLL_TAG = ""; public static final String XML_TAG = """ From 468aac3440e1b6bd6adf0a8d96747299e0dca653 Mon Sep 17 00:00:00 2001 From: Milenko Supic Date: Mon, 4 Sep 2023 15:32:36 +0200 Subject: [PATCH 4/6] Removed metadata for HTMLLayout, TTLLLayout and EchoLayout --- .../logback-classic/1.4.1/reflect-config.json | 92 ------------------- .../org/graalvm/logback/LogbackTests.java | 8 +- .../org/graalvm/logback/util/LayoutTags.java | 10 -- 3 files changed, 1 insertion(+), 109 deletions(-) diff --git a/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json b/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json index b02a1c5b7..a02ba785b 100644 --- a/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json +++ b/metadata/ch.qos.logback/logback-classic/1.4.1/reflect-config.json @@ -24,51 +24,6 @@ } ] }, - { - "name": "ch.qos.logback.classic.html.HTMLLayout", - "condition": { - "typeReachable": "ch.qos.logback.core.LayoutBase" - }, - "queryAllPublicMethods": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "ch.qos.logback.classic.html.UrlCssBuilder", - "condition": { - "typeReachable": "ch.qos.logback.core.LayoutBase" - }, - "queryAllPublicMethods": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - }, - { - "name": "setUrl", - "parameterTypes": [ - "java.lang.String" - ] - } - ] - }, - { - "name": "ch.qos.logback.classic.layout.TTLLLayout", - "condition": { - "typeReachable": "ch.qos.logback.core.LayoutBase" - }, - "queryAllPublicMethods": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, { "name": "ch.qos.logback.classic.log4j.XMLLayout", "condition": { @@ -529,53 +484,6 @@ } ] }, - { - "name": "ch.qos.logback.core.html.CssBuilder", - "condition": { - "typeReachable": "ch.qos.logback.core.LayoutBase" - }, - "methods": [ - { - "name": "valueOf", - "parameterTypes": [ - "java.lang.String" - ] - } - ] - }, - { - "name": "ch.qos.logback.core.html.HTMLLayoutBase", - "condition": { - "typeReachable": "ch.qos.logback.core.LayoutBase" - }, - "methods": [ - { - "name": "setCssBuilder", - "parameterTypes": [ - "ch.qos.logback.core.html.CssBuilder" - ] - }, - { - "name": "setPattern", - "parameterTypes": [ - "java.lang.String" - ] - } - ] - }, - { - "name": "ch.qos.logback.core.layout.EchoLayout", - "condition": { - "typeReachable": "ch.qos.logback.core.LayoutBase" - }, - "queryAllPublicMethods": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, { "name": "ch.qos.logback.core.pattern.IdentityCompositeConverter", "condition": { diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java index 0f6a926ae..6c7b44157 100644 --- a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java @@ -53,19 +53,13 @@ public class LogbackTests { private static final Map layoutTagMap = new HashMap<>(); static { - layoutTagMap.put("echoLayout", LayoutTags.ECHO_TAG); - layoutTagMap.put("htmlLayout", LayoutTags.HTML_TAG); layoutTagMap.put("patternLayout", LayoutTags.PATTERN_TAG); - layoutTagMap.put("ttllLayout", LayoutTags.TTLL_TAG); layoutTagMap.put("xmlLayout", LayoutTags.XML_TAG); } private static final Map layoutResultMap = new HashMap<>(); static { - layoutResultMap.put("echoLayout", "[INFO] test info message"); - layoutResultMap.put("htmlLayout", "test info message"); layoutResultMap.put("patternLayout", "#logback.classic pattern: %msg\ntest info message"); - layoutResultMap.put("ttllLayout", "INFO ROOT - test info message"); layoutResultMap.put("xmlLayout", "test info message"); } @@ -103,7 +97,7 @@ public void setUp() { } @ParameterizedTest - @ValueSource(strings = {"echoLayout", "htmlLayout", "patternLayout", "ttllLayout", "xmlLayout"}) + @ValueSource(strings = {"patternLayout", "xmlLayout"}) void testLayouts(String layoutName) throws Exception { LoggerContext testLoggerContext = new LoggerContext(); diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java index 153f11738..d7209b42f 100644 --- a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/util/LayoutTags.java @@ -21,22 +21,12 @@ public class LayoutTags { """; - public static final String ECHO_TAG = ""; - - public static final String HTML_TAG = """ - - %msg - test-url - """; - public static final String PATTERN_TAG = """ %msg true """; - public static final String TTLL_TAG = ""; - public static final String XML_TAG = """ true From f65180f438ac6de84375fe8b7194a2d6ba02266e Mon Sep 17 00:00:00 2001 From: Milenko Supic Date: Tue, 19 Sep 2023 14:35:24 +0200 Subject: [PATCH 5/6] Additional metadata for ch.qos.logback:logback-classic:1.4.9 --- .../logback-classic/1.4.9/reflect-config.json | 321 ++++++++++++++++++ 1 file changed, 321 insertions(+) diff --git a/metadata/ch.qos.logback/logback-classic/1.4.9/reflect-config.json b/metadata/ch.qos.logback/logback-classic/1.4.9/reflect-config.json index 6f7413b75..0909e5657 100644 --- a/metadata/ch.qos.logback/logback-classic/1.4.9/reflect-config.json +++ b/metadata/ch.qos.logback/logback-classic/1.4.9/reflect-config.json @@ -1,4 +1,17 @@ [ + { + "name": "ch.qos.logback.classic.PatternLayout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, { "name": "ch.qos.logback.classic.encoder.PatternLayoutEncoder", "condition": { @@ -23,6 +36,31 @@ } ] }, + { + "name": "ch.qos.logback.classic.log4j.XMLLayout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setLocationInfo", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "setProperties", + "parameterTypes": [ + "boolean" + ] + } + ] + }, { "name": "ch.qos.logback.classic.pattern.CallerDataConverter", "condition": { @@ -374,6 +412,57 @@ } ] }, + { + "name": "ch.qos.logback.core.FileAppender", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setAppend", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "setFile", + "parameterTypes": [ + "java.lang.String" + ] + }, + { + "name": "setPrudent", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.Layout", + "condition": { + "typeReachable": "ch.qos.logback.core.LayoutBase" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, { "name": "ch.qos.logback.core.OutputStreamAppender", "condition": { @@ -385,6 +474,12 @@ "parameterTypes": [ "ch.qos.logback.core.encoder.Encoder" ] + }, + { + "name": "setImmediateFlush", + "parameterTypes": [ + "boolean" + ] } ] }, @@ -393,7 +488,18 @@ "condition": { "typeReachable": "ch.qos.logback.core.joran.util.PropertySetter" }, + "queryAllPublicMethods": true, "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setLayout", + "parameterTypes": [ + "ch.qos.logback.core.Layout" + ] + }, { "name": "setParent", "parameterTypes": [ @@ -414,6 +520,26 @@ } ] }, + { + "name": "ch.qos.logback.core.pattern.PatternLayoutBase", + "condition": { + "typeReachable": "ch.qos.logback.core.model.processor.ImplicitModelHandler" + }, + "methods": [ + { + "name": "setOutputPatternAsHeader", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "setPattern", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, { "name": "ch.qos.logback.core.pattern.PatternLayoutEncoderBase", "condition": { @@ -631,5 +757,200 @@ "parameterTypes": [] } ] + }, + { + "name": "ch.qos.logback.core.rolling.RollingFileAppender", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setFile", + "parameterTypes": [ + "java.lang.String" + ] + }, + { + "name": "setRollingPolicy", + "parameterTypes": [ + "ch.qos.logback.core.rolling.RollingPolicy" + ] + }, + { + "name": "setTriggeringPolicy", + "parameterTypes": [ + "ch.qos.logback.core.rolling.TriggeringPolicy" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.RollingPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.RollingPolicyBase", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "setFileNamePattern", + "parameterTypes": [ + "java.lang.String" + ] + }, + { + "name": "setParent", + "parameterTypes": [ + "ch.qos.logback.core.FileAppender" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setMaxFileSize", + "parameterTypes": [ + "ch.qos.logback.core.util.FileSize" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "queryAllPublicMethods": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "setMaxFileSize", + "parameterTypes": [ + "ch.qos.logback.core.util.FileSize" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.TimeBasedRollingPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "setCleanHistoryOnStart", + "parameterTypes": [ + "boolean" + ] + }, + { + "name": "setMaxHistory", + "parameterTypes": [ + "int" + ] + }, + { + "name": "setTotalSizeCap", + "parameterTypes": [ + "ch.qos.logback.core.util.FileSize" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.TriggeringPolicy", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.helper.DateTokenConverter", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "ch.qos.logback.core.rolling.helper.IntegerTokenConverter", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "ch.qos.logback.core.spi.ContextAware", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "ch.qos.logback.core.util.FileSize", + "condition": { + "typeReachable": "ch.qos.logback.core.util.OptionHelper" + }, + "methods": [ + { + "name": "valueOf", + "parameterTypes": [ + "java.lang.String" + ] + } + ] } ] From e97518196137302d9c8a49e72c12332e910f1e3f Mon Sep 17 00:00:00 2001 From: Milenko Supic Date: Tue, 19 Sep 2023 17:45:14 +0200 Subject: [PATCH 6/6] Fixed tests --- .../org/graalvm/logback/LogbackTests.java | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java index 6c7b44157..8d45c9804 100644 --- a/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java +++ b/tests/src/ch.qos.logback/logback-classic/1.4.1/src/test/java/org/graalvm/logback/LogbackTests.java @@ -99,15 +99,13 @@ public void setUp() { @ParameterizedTest @ValueSource(strings = {"patternLayout", "xmlLayout"}) void testLayouts(String layoutName) throws Exception { - LoggerContext testLoggerContext = new LoggerContext(); - JoranConfigurator joranConfigurator = new JoranConfigurator(); - joranConfigurator.setContext(testLoggerContext); + joranConfigurator.setContext(context); String configXml = LayoutTags.CONFIG_TAG.formatted(layoutTagMap.get(layoutName)); joranConfigurator.doConfigure(new ByteArrayInputStream(configXml.getBytes())); - Logger testLogger = testLoggerContext.getLogger(Logger.ROOT_LOGGER_NAME); + Logger testLogger = context.getLogger(Logger.ROOT_LOGGER_NAME); testLogger.info("test info message"); String loggedMessage = outputStreamCaptor.toString(); @@ -116,17 +114,15 @@ void testLayouts(String layoutName) throws Exception { @Test void testFileAppender() throws Exception { - LoggerContext testLoggerContext = new LoggerContext(); - JoranConfigurator joranConfigurator = new JoranConfigurator(); - joranConfigurator.setContext(testLoggerContext); + joranConfigurator.setContext(context); String filePath = tempDirPath + "/log.txt"; String filesTag = AppenderTags.FILE_TAG.formatted(filePath); String configXml = AppenderTags.CONFIG_TAG.formatted(filesTag); joranConfigurator.doConfigure(new ByteArrayInputStream(configXml.getBytes())); - Logger testLogger = testLoggerContext.getLogger(Logger.ROOT_LOGGER_NAME); + Logger testLogger = context.getLogger(Logger.ROOT_LOGGER_NAME); testLogger.info("test info message"); String loggedMessage = Files.readAllLines(Paths.get(filePath)).get(0); @@ -135,37 +131,21 @@ void testFileAppender() throws Exception { @Test void testRollingFileAppender() throws Exception { - LoggerContext testLoggerContext = new LoggerContext(); - JoranConfigurator joranConfigurator = new JoranConfigurator(); - joranConfigurator.setContext(testLoggerContext); + joranConfigurator.setContext(context); String filePath = tempDirPath + "/rolling-log.txt"; String filesTag = AppenderTags.ROLLING_FILE_TAG.formatted(filePath); String configXml = AppenderTags.CONFIG_TAG.formatted(filesTag); joranConfigurator.doConfigure(new ByteArrayInputStream(configXml.getBytes())); - Logger testLogger = testLoggerContext.getLogger(Logger.ROOT_LOGGER_NAME); + Logger testLogger = context.getLogger(Logger.ROOT_LOGGER_NAME); testLogger.info("test info message"); String loggedMessage = Files.readAllLines(Paths.get(filePath)).get(0); assertThat(loggedMessage).isEqualTo("test info message"); } - @Test - void debugMessageLoggedViaExternalConfig() { - Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME); - logger.debug("test message"); - assertThat(outputStreamCaptor.toString()).isEqualTo("test message\n"); - } - - @Test - void traceMessageSkippedViaExternalConfig() { - Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME); - logger.trace("test message"); - assertThat(outputStreamCaptor.toString()).isBlank(); - } - @Test void consoleAppenderPropertySetter() { ConsoleAppender consoleAppender = new ConsoleAppender();