-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a test in relation with LOGBACK-1582
Signed-off-by: Ceki Gulcu <[email protected]>
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
logback-classic/src/test/java/ch/qos/logback/classic/pattern/CompositeConverterTest.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,62 @@ | ||
/** | ||
* Logback: the reliable, generic, fast and flexible logging framework. | ||
* Copyright (C) 1999-2022, QOS.ch. All rights reserved. | ||
* | ||
* This program and the accompanying materials are dual-licensed under | ||
* either the terms of the Eclipse Public License v1.0 as published by | ||
* the Eclipse Foundation | ||
* | ||
* or (per the licensee's choosing) | ||
* | ||
* under the terms of the GNU Lesser General Public License version 2.1 | ||
* as published by the Free Software Foundation. | ||
*/ | ||
package ch.qos.logback.classic.pattern; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
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; | ||
import ch.qos.logback.core.testUtil.StatusChecker; | ||
import ch.qos.logback.core.util.StatusPrinter; | ||
|
||
public class CompositeConverterTest { | ||
|
||
private PatternLayout pl = new PatternLayout(); | ||
private LoggerContext lc = new LoggerContext(); | ||
Logger logger = lc.getLogger(this.getClass()); | ||
StatusChecker sc = new StatusChecker(lc); | ||
|
||
|
||
@Before | ||
public void setUp() { | ||
pl.setContext(lc); | ||
} | ||
|
||
ILoggingEvent makeLoggingEvent(String msg, Exception ex) { | ||
return new LoggingEvent(CompositeConverterTest.class.getName(), logger, Level.INFO, msg, ex, null); | ||
} | ||
|
||
|
||
|
||
@Test | ||
public void testLogback1582() { | ||
// EVAL_REF is searched within the context, if context is not set (== null), then | ||
// a NullPointerException will be thrown | ||
pl.setPattern("%m %replace(%rootException{5, EVAL_REF}){'\\n', 'XYZ'}\""); | ||
pl.start(); | ||
ILoggingEvent le = makeLoggingEvent("assert", new Exception("test")); | ||
|
||
String result = pl.doLayout(le); | ||
sc.assertIsErrorFree(); | ||
assertTrue(result.contains("XYZ")); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...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