Skip to content

Commit

Permalink
ongoing work to enable AsyncAppender support in Joran
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Oct 24, 2019
1 parent 074e844 commit d85b5f7
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 6 deletions.
Expand Up @@ -62,9 +62,6 @@ public void addInstanceRules(RuleStore rs) {

rs.addRule(new ElementSelector("configuration"), new ConfigurationAction());
rs.addRule(new ElementSelector("configuration/appender-ref"), new AppenderRefAction());

//rs.addRule(new ElementSelector("configuration/appender/sift/*"), new NOPAction());

rs.addRule(new ElementSelector("configuration/include"), new IncludeModelAction());
}

Expand Down Expand Up @@ -122,6 +119,7 @@ private void injectModelFilters(DefaultProcessor defaultProcessor) {
fistPhaseDefintionFilter.denyAll();
defaultProcessor.setPhaseOneFilter(fistPhaseDefintionFilter);

// Note: AppenderModel is in the second phase

defaultProcessor.setPhaseTwoFilter(new AllowAllModelFilter());

Expand Down
Expand Up @@ -4,7 +4,6 @@
<configuration debug="false">

<appender name="A" class="ch.qos.logback.core.read.ListAppender"/>
<appender name="B" class="ch.qos.logback.core.read.ListAppender"/>

<logger name="ch.qos.logback.classic.joran" level="INFO">
<appender-ref ref="${logback.appenderRef}"/>
Expand Down
21 changes: 21 additions & 0 deletions logback-classic/src/test/input/joran/asyncAppender.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration debug="false">


<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>256</queueSize>
<includeCallerData>false</includeCallerData>
<appender-ref ref="LIST" />
</appender>

<appender name="LIST" class="ch.qos.logback.core.read.ListAppender"/>


<root level="debug">
<appender-ref ref="ASYNC" />
</root>


</configuration>
14 changes: 14 additions & 0 deletions logback-classic/src/test/input/joran/unreferencedAppender1.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration debug="false">

<appender name="A" class="ch.qos.logback.core.read.ListAppender"/>
<appender name="B" class="ch.qos.logback.core.read.ListAppender"/>


<root level="ERROR">
<appender-ref ref="A"/>
</root>

</configuration>
Expand Up @@ -27,6 +27,7 @@
import org.junit.Test;
import org.slf4j.MDC;

import ch.qos.logback.classic.AsyncAppender;
import ch.qos.logback.classic.ClassicTestConstants;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
Expand Down Expand Up @@ -132,15 +133,18 @@ public void appenderRefSettingBySystemProperty() throws JoranException {
final String propertyName = "logback.appenderRef";
System.setProperty(propertyName, "A");
configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "appenderRefByProperty.xml");
StatusPrinter.print(loggerContext);
final Logger logger = loggerContext.getLogger("ch.qos.logback.classic.joran");
final ListAppender<ILoggingEvent> listAppender = (ListAppender<ILoggingEvent>) logger.getAppender("A");
assertEquals(0, listAppender.list.size());
final String msg = "hello world";
logger.info(msg);

assertEquals(1, listAppender.list.size());
System.clearProperty(propertyName);
}


@Test
public void statusListener() throws JoranException {
configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "statusListener.xml");
Expand Down Expand Up @@ -479,4 +483,31 @@ public void appenderRefBeforeAppenderTest() throws JoranException {
assertEquals(msg, le.getMessage());
checker.assertIsErrorFree();
}

@Test
public void unreferencedAppendersShouldBeSkipped() throws JoranException {
configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "unreferencedAppender1.xml");

final ListAppender<ILoggingEvent> listAppenderA = (ListAppender<ILoggingEvent>) root.getAppender("A");
assertNotNull(listAppenderA);
StatusPrinter.print(loggerContext);
StatusChecker checker = new StatusChecker(loggerContext);
checker.assertContainsMatch(Status.WARN, "Appender named \\[B\\] not referenced. Skipping further processing.");
}


@Test
public void asynAppender() throws JoranException {
configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "asyncAppender.xml");

final AsyncAppender asyncAppender = (AsyncAppender) root.getAppender("ASYNC");
assertNotNull(asyncAppender);
StatusPrinter.print(loggerContext);

assertTrue(asyncAppender.isStarted());
StatusPrinter.print(loggerContext);

StatusChecker checker = new StatusChecker(loggerContext);
//checker.assertContainsMatch(Status.WARN, "Appender named \\[B\\] not referenced. Skipping further processing.");
}
}
Expand Up @@ -37,7 +37,7 @@ public void handle(InterpretationContext interpContext, Model model) throws Mode
this.appenderAttachable = appenderRefBag.get(appenderName);

if(this.appenderAttachable == null) {
addWarn("Processing appender named ["+appenderName+"] not referenced. Skipping.");
addWarn("Appender named ["+appenderName+"] not referenced. Skipping further processing.");
skipped = true;
return;
}
Expand Down
5 changes: 4 additions & 1 deletion logback-site/src/site/pages/news.html
Expand Up @@ -47,7 +47,10 @@ <h3>11th of October, 2019, Release of version 1.3.0-alpha5</h3>
<p>Joran, logback's configuration system, has been rewritten to
use an internal representation model which can be processed
separately. As a side-effect, logback configuration scripts are
now order-free. Given the breadth of the changes, support for
now largely order-free. For example, appenders can now be defined
after they are first referenced in a logger. Moreover,
unreferenced appenders are no longer instantiated. Given the
breadth of the changes in Joran codebase, support for
<code>SiftingAppender</code> and Groovy configuration have been
dropped temporarily.
</p>
Expand Down

0 comments on commit d85b5f7

Please sign in to comment.