Skip to content

Commit

Permalink
fix LOGBACK-1417
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Aug 13, 2021
1 parent e3671f3 commit ab33a14
Show file tree
Hide file tree
Showing 9 changed files with 472 additions and 400 deletions.
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration debug="true">

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d ${ab - %m%n</Pattern>
</layout>
</appender>

<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>

</configuration>

Expand Up @@ -22,6 +22,7 @@
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.pattern.PatternLayoutBase;
import ch.qos.logback.core.pattern.parser.test.AbstractPatternLayoutBaseTest;
import ch.qos.logback.core.spi.ScanException;
import ch.qos.logback.core.testUtil.StringListAppender;
import ch.qos.logback.core.util.OptionHelper;
import ch.qos.logback.core.util.StatusPrinter;
Expand Down Expand Up @@ -139,7 +140,7 @@ public void testWithLettersComingFromLog4j() {
}

@Test
public void mdcWithDefaultValue() {
public void mdcWithDefaultValue() throws ScanException {
String pattern = "%msg %mdc{foo} %mdc{bar:-[null]}";
pl.setPattern(OptionHelper.substVars(pattern, lc));
pl.start();
Expand Down Expand Up @@ -203,7 +204,7 @@ public void smokeReplace() {
}

@Test
public void replaceNewline() {
public void replaceNewline() throws ScanException {
String pattern = "%replace(A\nB){'\n', '\n\t'}";
String substPattern = OptionHelper.substVars(pattern, null, lc);
assertEquals(pattern, substPattern);
Expand Down
Expand Up @@ -434,6 +434,15 @@ public void sysProps() throws JoranException {
checker.assertIsErrorFree();
}

@Test
public void propsWithMissingRightCurlyBrace() throws JoranException {
System.setProperty("abc", "not important");
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
configurator.doConfigure(ClassicTestConstants.JORAN_INPUT_PREFIX + "propsMissingRightCurlyBrace.xml");
checker.assertContainsMatch(Status.ERROR, "Problem while parsing");
}

@Test
public void packageDataDisabledByConfigAttribute() throws JoranException {
String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX + "packagingDataDisabled.xml";
Expand Down
Expand Up @@ -30,6 +30,7 @@
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.PropertyContainer;
import ch.qos.logback.core.spi.ScanException;
import ch.qos.logback.core.util.OptionHelper;

/**
Expand Down Expand Up @@ -259,7 +260,13 @@ public String subst(String value) {
if (value == null) {
return null;
}
return OptionHelper.substVars(value, this, context);

try {
return OptionHelper.substVars(value, this, context);
} catch(ScanException|IllegalArgumentException e) {
addError("Problem while parsing ["+value+"]", e);
return value;
}
}

public void markStartOfNamedDependency(String name) {
Expand Down

0 comments on commit ab33a14

Please sign in to comment.