Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
- Loading branch information
Showing
4 changed files
with
165 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ack-classic/src/test/java/ch/qos/logback/classic/pattern/EnsureExceptionHandlingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ch.qos.logback.classic.pattern; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import ch.qos.logback.classic.Level; | ||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.PatternLayout; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.classic.spi.LoggingEvent; | ||
|
||
public class EnsureExceptionHandlingTest { | ||
|
||
private PatternLayout pl = new PatternLayout(); | ||
private LoggerContext lc = new LoggerContext(); | ||
Logger logger = lc.getLogger(this.getClass()); | ||
|
||
static final String XTH = "xth"; | ||
static final String XCC = "xcc"; | ||
|
||
@Before | ||
public void setUp() { | ||
pl.setContext(lc); | ||
pl.getInstanceConverterMap().put(XTH, XThrowableHandlingConverter.class.getName()); | ||
pl.getInstanceConverterMap().put(XCC, XCompositeConverter.class.getName()); | ||
} | ||
|
||
ILoggingEvent makeLoggingEvent(String msg, Exception ex) { | ||
return new LoggingEvent(EnsureExceptionHandlingTest.class.getName(), logger, | ||
Level.INFO, msg, ex, null); | ||
} | ||
|
||
@Test | ||
public void smoke() { | ||
pl.setPattern("%m %"+XTH+")"); | ||
pl.start(); | ||
ILoggingEvent le = makeLoggingEvent("assert", null); | ||
pl.doLayout(le); | ||
} | ||
|
||
@Test | ||
public void withinComposite() { | ||
pl.setPattern("%m %"+XCC+"(%"+XTH+")"); | ||
pl.start(); | ||
ILoggingEvent le = makeLoggingEvent("assert", null); | ||
pl.doLayout(le); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
logback-classic/src/test/java/ch/qos/logback/classic/pattern/XCompositeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ch.qos.logback.classic.pattern; | ||
|
||
import static org.junit.Assert.assertNull; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.pattern.CompositeConverter; | ||
|
||
public class XCompositeConverter extends CompositeConverter<ILoggingEvent>{ | ||
|
||
void assertNoNext() { | ||
assertNull("converter instance has next element", this.getNext()); | ||
} | ||
|
||
@Override | ||
protected String transform(ILoggingEvent event, String in) { | ||
if (event.getMessage().contains("assert")) | ||
assertNoNext(); | ||
return ""; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...ack-classic/src/test/java/ch/qos/logback/classic/pattern/XThrowableHandlingConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ch.qos.logback.classic.pattern; | ||
|
||
import static org.junit.Assert.assertNull; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
|
||
public class XThrowableHandlingConverter extends ThrowableHandlingConverter { | ||
|
||
void assertNoNext() { | ||
assertNull("has next", this.getNext()); | ||
} | ||
|
||
@Override | ||
public String convert(ILoggingEvent event) { | ||
if (event.getMessage().contains("assert")) | ||
assertNoNext(); | ||
return ""; | ||
} | ||
|
||
} |