Skip to content

Commit

Permalink
fix issues/805 i.e. LOGBACK-1768, included file with inner conditional
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Apr 17, 2024
1 parent 3d55638 commit 759fc25
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

<!--
~ Logback: the reliable, generic, fast and flexible logging framework.
~ Copyright (C) 1999-2024, QOS.ch. All rights reserved.
~
~ This program and the accompanying materials are dual-licensed under
~ either the terms of the Eclipse Public License v1.0 as published by
~ the Eclipse Foundation
~
~ or (per the licensee's choosing)
~
~ under the terms of the GNU Lesser General Public License version 2.1
~ as published by the Free Software Foundation.
-->

<configuration>


<variable scope="system" name="JO_PREFIX" value="src/test/blackboxInput/joran"/>

<include file="${JO_PREFIX}/conditional/includedWithInnerConditional.xml"/>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
~ Logback: the reliable, generic, fast and flexible logging framework.
~ Copyright (C) 1999-2024, QOS.ch. All rights reserved.
~
~ This program and the accompanying materials are dual-licensed under
~ either the terms of the Eclipse Public License v1.0 as published by
~ the Eclipse Foundation
~
~ or (per the licensee's choosing)
~
~ under the terms of the GNU Lesser General Public License version 2.1
~ as published by the Free Software Foundation.
-->

<included>
<if condition="true">
<then>
<appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<root>
<appender-ref ref="CON"/>
</root>
</then>
</if>
</included>
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,28 @@ public void conditionalInclusionWithVariableDefinition() throws JoranException,
+ "conditional/includeWithVariableAndConditional.xml";
configure(configFileAsStr);

statusPrinter2.print(loggerContext);
//statusPrinter2.print(loggerContext);

ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) root.getAppender("CON");
assertNotNull(consoleAppender);
assertTrue(checker.isErrorFree(0));
}


// 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<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) root.getAppender("CON");
assertNotNull(consoleAppender);
assertTrue(checker.isErrorFree(0));
}

private AppenderTracker<ILoggingEvent> getAppenderTracker() {
SiftingAppender ha = (SiftingAppender) root.getAppender("SIFT");
return ha.getAppenderTracker();
Expand All @@ -192,4 +206,5 @@ public void nestedWithinIfThen() throws JoranException {
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,26 @@ public Supplier<Action> matchActions(ElementPath elementPath) {
return actionSupplier;
}

actionSupplier = matchActionsWithoutTransparentParts(elementPath);
if(actionSupplier != null) {
return actionSupplier;
}

return matchActionsWithRenamedParts(elementPath);

return matchActionsWithoutTransparentPartsAndRenamedParts(elementPath);
}

private Supplier<Action> matchActionsWithoutTransparentParts(ElementPath elementPath) {
private Supplier<Action> matchActionsWithoutTransparentPartsAndRenamedParts(ElementPath elementPath) {
ElementPath cleanedElementPath = removeTransparentPathParts(elementPath);
return internalMatchAction(cleanedElementPath);
}
ElementPath renamePathParts = renamePathParts(cleanedElementPath);

private Supplier<Action> matchActionsWithRenamedParts(ElementPath elementPath) {
ElementPath renamedElementPath = renamePathParts(elementPath);
return internalMatchAction(renamedElementPath);
return internalMatchAction(renamePathParts);
}

// private Supplier<Action> matchActionsWithoutTransparentParts(ElementPath elementPath) {
// ElementPath cleanedElementPath = removeTransparentPathParts(elementPath);
// return internalMatchAction(cleanedElementPath);
// }
//
// private Supplier<Action> matchActionsWithRenamedParts(ElementPath elementPath) {
// ElementPath renamedElementPath = renamePathParts(elementPath);
// return internalMatchAction(renamedElementPath);
// }

private Supplier<Action> internalMatchAction(ElementPath elementPath) {
Supplier<Action> actionSupplier;

Expand Down

0 comments on commit 759fc25

Please sign in to comment.