Skip to content

Commit 759fc25

Browse files
committed
fix issues/805 i.e. LOGBACK-1768, included file with inner conditional
Signed-off-by: Ceki Gulcu <[email protected]>
1 parent 3d55638 commit 759fc25

File tree

4 files changed

+81
-14
lines changed

4 files changed

+81
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
<!--
3+
~ Logback: the reliable, generic, fast and flexible logging framework.
4+
~ Copyright (C) 1999-2024, QOS.ch. All rights reserved.
5+
~
6+
~ This program and the accompanying materials are dual-licensed under
7+
~ either the terms of the Eclipse Public License v1.0 as published by
8+
~ the Eclipse Foundation
9+
~
10+
~ or (per the licensee's choosing)
11+
~
12+
~ under the terms of the GNU Lesser General Public License version 2.1
13+
~ as published by the Free Software Foundation.
14+
-->
15+
16+
<configuration>
17+
18+
19+
<variable scope="system" name="JO_PREFIX" value="src/test/blackboxInput/joran"/>
20+
21+
<include file="${JO_PREFIX}/conditional/includedWithInnerConditional.xml"/>
22+
23+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
~ Logback: the reliable, generic, fast and flexible logging framework.
3+
~ Copyright (C) 1999-2024, QOS.ch. All rights reserved.
4+
~
5+
~ This program and the accompanying materials are dual-licensed under
6+
~ either the terms of the Eclipse Public License v1.0 as published by
7+
~ the Eclipse Foundation
8+
~
9+
~ or (per the licensee's choosing)
10+
~
11+
~ under the terms of the GNU Lesser General Public License version 2.1
12+
~ as published by the Free Software Foundation.
13+
-->
14+
15+
<included>
16+
<if condition="true">
17+
<then>
18+
<appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
19+
<encoder>
20+
<pattern>%d %-5level %logger{35} - %msg %n</pattern>
21+
</encoder>
22+
</appender>
23+
<root>
24+
<appender-ref ref="CON"/>
25+
</root>
26+
</then>
27+
</if>
28+
</included>

logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/joran/conditional/ConditionalTest.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,28 @@ public void conditionalInclusionWithVariableDefinition() throws JoranException,
162162
+ "conditional/includeWithVariableAndConditional.xml";
163163
configure(configFileAsStr);
164164

165-
statusPrinter2.print(loggerContext);
165+
//statusPrinter2.print(loggerContext);
166166

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

172172

173+
// https://github.com/qos-ch/logback/issues/805
174+
@Test
175+
public void includedWithNestedConditional() throws JoranException {
176+
177+
String configFileAsStr = BlackboxClassicTestConstants.JORAN_INPUT_PREFIX
178+
+ "conditional/includeWithInnerConditional.xml";
179+
180+
configure(configFileAsStr);
181+
//statusPrinter2.print(loggerContext);
182+
ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) root.getAppender("CON");
183+
assertNotNull(consoleAppender);
184+
assertTrue(checker.isErrorFree(0));
185+
}
186+
173187
private AppenderTracker<ILoggingEvent> getAppenderTracker() {
174188
SiftingAppender ha = (SiftingAppender) root.getAppender("SIFT");
175189
return ha.getAppenderTracker();
@@ -192,4 +206,5 @@ public void nestedWithinIfThen() throws JoranException {
192206
}
193207

194208

209+
195210
}

logback-core/src/main/java/ch/qos/logback/core/joran/spi/SimpleRuleStore.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,26 @@ public Supplier<Action> matchActions(ElementPath elementPath) {
117117
return actionSupplier;
118118
}
119119

120-
actionSupplier = matchActionsWithoutTransparentParts(elementPath);
121-
if(actionSupplier != null) {
122-
return actionSupplier;
123-
}
124-
125-
return matchActionsWithRenamedParts(elementPath);
126-
120+
return matchActionsWithoutTransparentPartsAndRenamedParts(elementPath);
127121
}
128122

129-
private Supplier<Action> matchActionsWithoutTransparentParts(ElementPath elementPath) {
123+
private Supplier<Action> matchActionsWithoutTransparentPartsAndRenamedParts(ElementPath elementPath) {
130124
ElementPath cleanedElementPath = removeTransparentPathParts(elementPath);
131-
return internalMatchAction(cleanedElementPath);
132-
}
125+
ElementPath renamePathParts = renamePathParts(cleanedElementPath);
133126

134-
private Supplier<Action> matchActionsWithRenamedParts(ElementPath elementPath) {
135-
ElementPath renamedElementPath = renamePathParts(elementPath);
136-
return internalMatchAction(renamedElementPath);
127+
return internalMatchAction(renamePathParts);
137128
}
138129

130+
// private Supplier<Action> matchActionsWithoutTransparentParts(ElementPath elementPath) {
131+
// ElementPath cleanedElementPath = removeTransparentPathParts(elementPath);
132+
// return internalMatchAction(cleanedElementPath);
133+
// }
134+
//
135+
// private Supplier<Action> matchActionsWithRenamedParts(ElementPath elementPath) {
136+
// ElementPath renamedElementPath = renamePathParts(elementPath);
137+
// return internalMatchAction(renamedElementPath);
138+
// }
139+
139140
private Supplier<Action> internalMatchAction(ElementPath elementPath) {
140141
Supplier<Action> actionSupplier;
141142

0 commit comments

Comments
 (0)