|
26 | 26 | import java.util.List; |
27 | 27 | import java.util.Locale; |
28 | 28 | import java.util.ResourceBundle; |
| 29 | + |
29 | 30 | import org.apache.logging.log4j.core.Appender; |
30 | 31 | import org.apache.logging.log4j.core.LogEvent; |
31 | 32 | import org.apache.logging.log4j.core.LoggerContext; |
32 | 33 | import org.apache.logging.log4j.core.appender.AbstractAppender; |
33 | 34 | import org.apache.logging.log4j.core.config.ConfigurationFactory; |
| 35 | +import org.apache.logging.log4j.core.config.Configurator; |
34 | 36 | import org.apache.logging.log4j.core.config.Property; |
35 | 37 | import org.apache.logging.log4j.core.layout.PatternLayout; |
36 | 38 | import org.apache.logging.log4j.core.test.appender.ListAppender; |
37 | 39 | import org.junit.After; |
38 | 40 | import org.junit.AfterClass; |
| 41 | +import org.junit.Before; |
39 | 42 | import org.junit.BeforeClass; |
40 | 43 | import org.junit.Test; |
41 | 44 |
|
@@ -76,8 +79,10 @@ public static void tearDownClass() { |
76 | 79 | } |
77 | 80 |
|
78 | 81 | @After |
79 | | - public void tearDown() { |
| 82 | + @Before |
| 83 | + public void resetTest() { |
80 | 84 | LoggerContext.getContext().reconfigure(); |
| 85 | + Configurator.setAllLevels(Logger.getRootLogger().getName(), org.apache.logging.log4j.Level.DEBUG); |
81 | 86 | a1 = null; |
82 | 87 | a2 = null; |
83 | 88 | } |
@@ -493,6 +498,48 @@ public void testLog() { |
493 | 498 | } |
494 | 499 | } |
495 | 500 |
|
| 501 | + @Test |
| 502 | + public void testSetLevel() { |
| 503 | + final Logger a = Logger.getLogger("a"); |
| 504 | + final Logger a_b = Logger.getLogger("a.b"); |
| 505 | + final Logger a_b_c = Logger.getLogger("a.b.c"); |
| 506 | + // test default for this test |
| 507 | + assertEquals(Level.DEBUG, a.getLevel()); |
| 508 | + assertEquals(Level.DEBUG, a_b.getLevel()); |
| 509 | + assertEquals(Level.DEBUG, a_b_c.getLevel()); |
| 510 | + // all |
| 511 | + for (Level level : new Level[] { /*Level.ALL,*/ Level.DEBUG, Level.ERROR, Level.FATAL, Level.INFO, /*Level.OFF,*/ Level.TRACE, Level.WARN }) { |
| 512 | + a.setLevel(level); |
| 513 | + assertTrue(level.toString(), a.isEnabledFor(level)); |
| 514 | + assertTrue(level.toString(), a_b.isEnabledFor(level)); |
| 515 | + assertTrue(level.toString(), a_b_c.isEnabledFor(level)); |
| 516 | + assertEquals(level, a.getLevel()); |
| 517 | + assertEquals(Level.DEBUG, a_b.getLevel()); |
| 518 | + assertEquals(Level.DEBUG, a_b_c.getLevel()); |
| 519 | + } |
| 520 | + } |
| 521 | + |
| 522 | + @Test |
| 523 | + public void testSetPriority() { |
| 524 | + final Logger a = Logger.getLogger("a"); |
| 525 | + final Logger a_b = Logger.getLogger("a.b"); |
| 526 | + final Logger a_b_c = Logger.getLogger("a.b.c"); |
| 527 | + // test default for this test |
| 528 | + assertEquals(Priority.DEBUG, a.getPriority()); |
| 529 | + assertEquals(Priority.DEBUG, a_b.getPriority()); |
| 530 | + assertEquals(Priority.DEBUG, a_b_c.getPriority()); |
| 531 | + // all |
| 532 | + for (Priority level : Level.getAllPossiblePriorities()) { |
| 533 | + a.setPriority(level); |
| 534 | + assertTrue(level.toString(), a.isEnabledFor(level)); |
| 535 | + assertTrue(level.toString(), a_b.isEnabledFor(level)); |
| 536 | + assertTrue(level.toString(), a_b_c.isEnabledFor(level)); |
| 537 | + assertEquals(level, a.getLevel()); |
| 538 | + assertEquals(Priority.DEBUG, a_b.getPriority()); |
| 539 | + assertEquals(Priority.DEBUG, a_b_c.getPriority()); |
| 540 | + } |
| 541 | + } |
| 542 | + |
496 | 543 | private static class MyLogger { |
497 | 544 |
|
498 | 545 | private final Logger logger; |
|
0 commit comments