-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix SLF4J-546, Fluent logging API doesn't populate timestamp with Rel…
…oad4JLogger Signed-off-by: Ceki Gulcu <ceki@qos.ch>
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 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
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
61 changes: 61 additions & 0 deletions
61
slf4j-reload4j/src/test/java/org/slf4j/reload4j/EventFieldsTest.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,61 @@ | ||
package org.slf4j.reload4j; | ||
|
||
import org.apache.log4j.spi.LoggingEvent; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class EventFieldsTest { | ||
|
||
// value of LogManager.DEFAULT_CONFIGURATION_KEY; | ||
static String CONFIG_FILE_KEY = "log4j.configuration"; | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
System.clearProperty(CONFIG_FILE_KEY); | ||
} | ||
|
||
@Test | ||
public void testWhetherEventsFieldsAreSet() { | ||
System.setProperty(CONFIG_FILE_KEY, "eventFields.properties"); | ||
Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
logger.info("hello"); | ||
logger.atInfo().setMessage("hello").log(); | ||
|
||
org.slf4j.reload4j.Reload4jLoggerAdapter rootReload4j = (org.slf4j.reload4j.Reload4jLoggerAdapter) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); | ||
|
||
|
||
ListAppender listAppender = (ListAppender) rootReload4j.logger.getAppender("LIST"); | ||
|
||
assertNotNull(listAppender); | ||
assertNotNull(listAppender.list); | ||
|
||
List<LoggingEvent> eventList = listAppender.list; | ||
|
||
assertEquals(2, eventList.size()); | ||
|
||
LoggingEvent loggingEvent0 = eventList.get(0); | ||
long timeStamp0 = loggingEvent0.getTimeStamp(); | ||
String threadName0 = loggingEvent0.getThreadName(); | ||
assertTrue(timeStamp0 != 0); | ||
assertNotNull(threadName0); | ||
assertFalse(threadName0.isEmpty()); | ||
|
||
LoggingEvent loggingEvent1 = eventList.get(1); | ||
long timeStamp1 = loggingEvent1.getTimeStamp(); | ||
String threadName1 = loggingEvent1.getThreadName(); | ||
assertTrue(timeStamp1 != 0); | ||
assertTrue(timeStamp1 >= timeStamp0); | ||
assertNotNull(threadName1); | ||
assertFalse(threadName1.isEmpty()); | ||
assertEquals(threadName0, threadName1); | ||
|
||
} | ||
|
||
|
||
} |
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,4 @@ | ||
log4j.debug=true | ||
log4j.rootLogger=DEBUG, LIST | ||
|
||
log4j.appender.LIST=org.slf4j.reload4j.ListAppender |