From 759fc25ee384354a9159e64aa1fb7269d770fce4 Mon Sep 17 00:00:00 2001 From: Ceki Gulcu Date: Wed, 17 Apr 2024 17:43:33 +0200 Subject: [PATCH] fix issues/805 i.e. LOGBACK-1768, included file with inner conditional Signed-off-by: Ceki Gulcu --- .../includeWithInnerConditional.xml | 23 +++++++++++++++ .../includedWithInnerConditional.xml | 28 +++++++++++++++++++ .../joran/conditional/ConditionalTest.java | 17 ++++++++++- .../core/joran/spi/SimpleRuleStore.java | 27 +++++++++--------- 4 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 logback-classic-blackbox/src/test/blackboxInput/joran/conditional/includeWithInnerConditional.xml create mode 100644 logback-classic-blackbox/src/test/blackboxInput/joran/conditional/includedWithInnerConditional.xml diff --git a/logback-classic-blackbox/src/test/blackboxInput/joran/conditional/includeWithInnerConditional.xml b/logback-classic-blackbox/src/test/blackboxInput/joran/conditional/includeWithInnerConditional.xml new file mode 100644 index 0000000000..40bfb7185e --- /dev/null +++ b/logback-classic-blackbox/src/test/blackboxInput/joran/conditional/includeWithInnerConditional.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/logback-classic-blackbox/src/test/blackboxInput/joran/conditional/includedWithInnerConditional.xml b/logback-classic-blackbox/src/test/blackboxInput/joran/conditional/includedWithInnerConditional.xml new file mode 100644 index 0000000000..c7901a3d53 --- /dev/null +++ b/logback-classic-blackbox/src/test/blackboxInput/joran/conditional/includedWithInnerConditional.xml @@ -0,0 +1,28 @@ + + + + + + + + %d %-5level %logger{35} - %msg %n + + + + + + + + \ No newline at end of file diff --git a/logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/joran/conditional/ConditionalTest.java b/logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/joran/conditional/ConditionalTest.java index 8c2cb7b382..b60181105f 100644 --- a/logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/joran/conditional/ConditionalTest.java +++ b/logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/joran/conditional/ConditionalTest.java @@ -162,7 +162,7 @@ public void conditionalInclusionWithVariableDefinition() throws JoranException, + "conditional/includeWithVariableAndConditional.xml"; configure(configFileAsStr); - statusPrinter2.print(loggerContext); + //statusPrinter2.print(loggerContext); ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON"); assertNotNull(consoleAppender); @@ -170,6 +170,20 @@ public void conditionalInclusionWithVariableDefinition() throws JoranException, } + // https://github.com/qos-ch/logback/issues/805 + @Test + public void includedWithNestedConditional() throws JoranException { + + String configFileAsStr = BlackboxClassicTestConstants.JORAN_INPUT_PREFIX + + "conditional/includeWithInnerConditional.xml"; + + configure(configFileAsStr); + //statusPrinter2.print(loggerContext); + ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON"); + assertNotNull(consoleAppender); + assertTrue(checker.isErrorFree(0)); + } + private AppenderTracker getAppenderTracker() { SiftingAppender ha = (SiftingAppender) root.getAppender("SIFT"); return ha.getAppenderTracker(); @@ -192,4 +206,5 @@ public void nestedWithinIfThen() throws JoranException { } + } diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SimpleRuleStore.java b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SimpleRuleStore.java index 563cb47f19..e28a633f00 100755 --- a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SimpleRuleStore.java +++ b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SimpleRuleStore.java @@ -117,25 +117,26 @@ public Supplier matchActions(ElementPath elementPath) { return actionSupplier; } - actionSupplier = matchActionsWithoutTransparentParts(elementPath); - if(actionSupplier != null) { - return actionSupplier; - } - - return matchActionsWithRenamedParts(elementPath); - + return matchActionsWithoutTransparentPartsAndRenamedParts(elementPath); } - private Supplier matchActionsWithoutTransparentParts(ElementPath elementPath) { + private Supplier matchActionsWithoutTransparentPartsAndRenamedParts(ElementPath elementPath) { ElementPath cleanedElementPath = removeTransparentPathParts(elementPath); - return internalMatchAction(cleanedElementPath); - } + ElementPath renamePathParts = renamePathParts(cleanedElementPath); - private Supplier matchActionsWithRenamedParts(ElementPath elementPath) { - ElementPath renamedElementPath = renamePathParts(elementPath); - return internalMatchAction(renamedElementPath); + return internalMatchAction(renamePathParts); } +// private Supplier matchActionsWithoutTransparentParts(ElementPath elementPath) { +// ElementPath cleanedElementPath = removeTransparentPathParts(elementPath); +// return internalMatchAction(cleanedElementPath); +// } +// +// private Supplier matchActionsWithRenamedParts(ElementPath elementPath) { +// ElementPath renamedElementPath = renamePathParts(elementPath); +// return internalMatchAction(renamedElementPath); +// } + private Supplier internalMatchAction(ElementPath elementPath) { Supplier actionSupplier;