Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>

<x>
<stack name="BEGIN"/>
<if>
<condition class="ch.qos.logback.core.boolex.ExpressionPropertyCondition">
<expression>propertyEquals("ki1", "val1")</expression>
</condition>
<then>
<stack name="a"/>
</then>
</if>
<stack name="END"/>
</x>
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ public void whenNoPropertyIsDefined_ElseBranchIsEvaluated_NoJoran() throws Joran
simpleConfigurator.doConfigure(CONDITIONAL_DIR_PREFIX + "if0_NoJoran.xml");
verifyConfig(new String[] { "BEGIN", "b", "END" });
}

@Test
public void conditionNestedWithinIfProducesWarning() throws JoranException {
simpleConfigurator.doConfigure(CONDITIONAL_DIR_PREFIX + "conditionInsideIf.xml");
assertTrue(checker.containsMatch(Status.WARN,
"The <condition> element must be placed before the <if> element, not inside it."));
verifyConfig(new String[] { "BEGIN", "END" });
}

// ----------------------------------------------------------------------------------------------------

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.joran.conditional.Condition;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.conditional.ByPropertiesConditionModel;
import ch.qos.logback.core.model.conditional.IfModel;
import ch.qos.logback.core.model.conditional.IfModel.BranchState;
import ch.qos.logback.core.model.processor.ModelHandlerBase;
Expand Down Expand Up @@ -63,6 +64,10 @@ protected Class<IfModel> getSupportedModelClass() {
public void handle(ModelInterpretationContext mic, Model model) throws ModelHandlerException {

ifModel = (IfModel) model;
if (ifModel.getSubModels().stream().anyMatch(ByPropertiesConditionModel.class::isInstance)) {
addWarn("The <condition> element must be placed before the <if> element, not inside it.");
}

mic.pushModel(ifModel);
Object micTopObject = mic.peekObject();
String conditionStr = ifModel.getCondition();
Expand Down